gpt4 book ai didi

javascript - Uncaught Error : Method "undefined" does not exist backbone. js:1291

转载 作者:行者123 更新时间:2023-12-02 19:17:36 25 4
gpt4 key购买 nike

现在真的很摸不着头脑。下面的backbone.js代码有什么问题?它不断提示“未捕获错误:方法“未定义”不存在backbone.js:1291”

失败代码在这里:http://jsfiddle.net/toeinriver/ntK7r/19/

(function($){
var Person = Backbone.Model.extend({
defaults:{
age: 0,
name: "tom"
}
});

var People = Backbone.Collection.extend({
model: Person});

ListView = Backbone.View.extend({
el: $("body"),
events: {
"click button#btn": this.addItem
},
initialize: function(){
this.count = 0;
_.bindAll(this, "render", "appendItem","addItem");
this.collection = new People();
this.collection.bind("add", this.appendItem);
this.counter = 0;
this.render();
},
render: function(){
var self = this;
$(this.el).append("<button id='btn'>Press me</button>");
$(this.el).append("<ul></ul>");
_(this.collection.models).each(function(item){
self.appendItem(item);
this.count+=1;
},this);
},
appendItem: function(item){
$("ul", this.el).append("<li>" + item.get("name") +" at" + item.get("age") + "</li>");
},
addItem: function(){
var p = new Person();
p.set({age:this.count});
this.count += 1;
this.collection.add(p);
}
});

var listView = new ListView();


})(jQuery);

最佳答案

events: {
"click button#btn": "addItem"
},

关于javascript - Uncaught Error : Method "undefined" does not exist backbone. js:1291,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12945831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com