无法使用在backbonejs集合create方法 [英] unable to use create method on collections in backbonejs
本文介绍了无法使用在backbonejs集合create方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的骨干集合:
app.ledgerList=Backbone.Collection.extend({
model: app.ledger,
localStorage:new Store('ledgers')
});
///initializing
app.ledgers=new app.ledgerList();
和在我后面的应用程序视图中的一个,我有:
And in one of my views later in app, i have:
saveLedger: function(){
name=$("#ledgerName").val();
email=$("#ledgerEmail").val();
address=$("#ledgerAddress").val();
phone=$("#ledgerPhone").val();
console.log(app.ledgers.length);
app.ledgers.create({name:name,email:email,address:address,phone:phone});
}
这将返回我的未捕获类型错误:对象的翻译:具有线路上无法适用
app.ledgers.create({名:姓名,电子邮件:电子邮件,地址:地址,电话:电话})
可能是什么问题?
This returns me Uncaught TypeError: Object [object Object] has no method 'apply'
on the line app.ledgers.create({name:name,email:email,address:address,phone:phone})
What may be the problem?
推荐答案
它看起来像当时你调用创建()
的 app.ledgers
不再是一个集合。你应该的console.log(app.ledgers)
正上方的Create()语句。
It looks like at the time you're calling create()
that app.ledgers
is no longer a Collection. You should console.log(app.ledgers)
right above the create() statement.
这篇关于无法使用在backbonejs集合create方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文