我的视图出现错误,其中 var campaign = new CampaginModel() 没有获取模型。
使用 require.js + 主干:
错误:
未捕获的类型错误:对象 [对象对象] 没有方法“获取”
当我安慰console.log(CampaginModel)
我得到的对象时function (){return i.apply(this,arguments)}
,它是完全不正确的,因为它应该是模型的一个实例。
我在这里做错了什么?
型号(型号/CampaginModel):
define([
'underscore',
'backbone'
], function(_, Backbone) {
var CampaginModel = Backbone.Model.extend({
urlRoot: '/api/v1/campaign/'
});
return CampaginModel;
});
看法:
define([
'jquery',
'underscore',
'backbone',
'views/RewardView',
'views/FriendRewardView',
'models/CampaginModel',
'text!templates/backbone/portal/campaignTemplate.html'
], function($, _, Backbone, campaignTemplate, CampaginModel){
var CampaginView = Backbone.View.extend({
el: '#campaign-panel',
render: function(options) {
if(options.id){
var campaign = new CampaginModel({id: options.id});
campaign.fetch({
success: function(campaign){
}// end success
}); // end fetch
}// end if option.id
} // end render function
}); // end campagin view
return CampaginView;
});
主.js:
require.config({
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone',
init: function (_, $) { Backbone.$ = $; return Backbone; }
}
},
paths: {
jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min',
underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min',
backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min',
templates: '/templates/'
}
});
require([
'app'
], function(App){
App.initialize();
});