gpt4 book ai didi

jquery - Backbone - 对象渲染没有方法 'apply'

转载 作者:行者123 更新时间:2023-12-03 22:41:19 25 4
gpt4 key购买 nike

我收到错误:

object render has no method apply for the below code.

可能是什么原因?除了 javascript 的链接之外,html 页面不包含任何代码。
我应该怎么做才能消除错误?

(function($) {

window.Book = Backbone.Model.extend({});

window.Library = Backbone.Collection.extend({

model: Book

}); // end of Collection
window.LibraryView = Backbone.View.extend({

el: $('body'),

events: {
'click button#btn_add': 'btn_add'

},

initialize: function() {
$(this.el).append("View initialized");
_.bindAll(this, 'render', 'btn_add');
this.collections = new Library();
this.collections.bind('add', 'render', this);
this.startingDisplay();

},
startingDisplay: function() {
$(this.el).append("<input type='text' id='t1' /><button id='btn_add'>Add</button>");

},

btn_add: function() {

book = new Book({
title: "first"
});
alert("Name : " + book.get('title'));
this.collections.add(book);
},

render: function() {
alert("render called");

},

}); // end of LibraryView
libraryview = new LibraryView();

})(jQuery);​

最佳答案

您没有使用正确的语法来绑定(bind) add 集合事件。使用:

// this.collections.bind('add', 'render', this);
this.collections.bind('add', this.render, this);

第二个参数应该是回调(函数)。

<强> DEMO

关于jquery - Backbone - 对象渲染没有方法 'apply',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9962723/

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