问题描述
Featoff = can.Model.extend("featoff",{
findAll: {
url: '/api.php/specialoffers?',
type: 'GET',
data: { max : 10 , pid : 977 , sid : 5934 }
}
}, {});
Feat = can.Control({ init: function()
{ var that = this; can.view('images/js/mn/temps/featured.ejs', featoff.findAll({}).then(function(d)
{ return { offerdata : d, secTitle : that.element.data('title') }; })).done(function(frag)
{ that.element.html(frag); }) }});
我正在使用新的Feat()来调用它;
I am calling this using new Feat();
这现在正在工作.因此,现在我想在findAll中使用相同的Feat控件和不同的参数集重复使用,我该怎么做?使用什么方法以及如何使用?我也可以针对相同的??推迟或覆盖can.view吗?
this is working now. So now I wanna reuse the same Feat control with different set of parameters in the findAll, How can i do so? What method to use and how to use?? also can I also defer or override the can.view for the same ??
我还可以拥有一个Base控制器,并继续覆盖参数吗?
Can I also have a single Base controller and just keep overriding the parameters?
推荐答案
要覆盖视图,可以扩展Feat对象FeatExtended = Feat.extend{
并在init方法中使用其他视图.
To override the view you can extend your Feat object FeatExtended = Feat.extend{
and use a different view in the init method.
您也可以在调用new Feat({view : MY_VIEW})
时提供参数.根据此处的说明,将选项对象传递给init().
You can also give parameters when calling new Feat({view : MY_VIEW})
. An options object is passed to init() as describe here.
对于您的findAll问题,您应该将findAll定义为中描述的方法.文档
For you findAll question, you should define findAll as a method as describe in the documentation
希望有帮助!
例如:您可以传递一个params对象,该对象定义要在URL中添加的选项以及HTTP调用的方法
For example : you can pass a params object defining an option to be added in URL and the method of the HTTP call
Featoff = can.Model.extend({
findAll : function(params){
return $.ajax({
url: '/api.php/specialoffers?' + params.myoption,
type: params.method,
dataType: 'json'})
}
},{})
这篇关于如何在CanJS中使用Defer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!