出于某种原因,this.model 在我的 editUsp 方法中不起作用。我想用 .set 更改模型中的值。
有谁知道,我做错了什么?
我收到此错误:
Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'set'
这是代码:
var Usp = Backbone.Model.extend();
var widgetView = Backbone.View.extend({
model: Usp,
initialize: function (data,collection) {
var usp = new Usp({type:'usp', items: data});
collection.add(usp);
this.render(data);
},
events: {
"click .edit": "editUsp",
},
editUsp: function(){
this.model.set({type:'uspsss',items: 'hoi'});
},
render: function(data){
var uspList = '<ul>';
$.each(data['Usps'], function(i,item){
uspList += '<li>'+item+'</li>';
});
var template = _.template('<div class="block"><a class="edit"><i class="icon-edit"></i> Edit </a><%= uspList %></div>');
var widgetView = template({uspList: uspList});
this.setElement(widgetView);
$('.laySidebar .smallBlocks').append($(this.el).hide().fadeIn(700));
}
});