unable to use create method on collections in backbonejs

大憨熊 提交于 2019-12-08 01:57:02

问题


I have a collection in backbone like this:

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});
}

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?


回答1:


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.



来源:https://stackoverflow.com/questions/14422433/unable-to-use-create-method-on-collections-in-backbonejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!