Uncaught TypeError: Cannot read property 'loca

2019-05-10 11:21发布

问题:

I have the following in the backbonejs app:

////MODEL
var app={};
app.ledger=Backbone.Model.extend();

////COLLECTION
app.ledgerList=Backbone.Collection.extend({
model: app.ledger,
localStorage:new Store('ledgerstore')
 });

////INITIATING COLLECTION
app.ledgerlist=new app.ledgerList();

In one of my views i try to create a new model in the collection like this:

newAttributes:function(){
    return{
        name:$("#ledgerName").val(),
        email: $("#ledgerEmail").val(),
        address: $("#ledgerAddress").val(),
        phone: $("#ledgerPhone").val()

     }},
saveLedger: function(){
    app.ledgerlist.create(this.newAttributes());


}

I get the error Uncaught TypeError: Cannot read property 'localStorage' of undefined on the line app.ledgerlist.create(this.newAttributes());

It all started occuring suddenly out of nowhere. It was working a few mins back. I guess it has to do something with localstorage. I cleared it but still the same. In firefox console says d.collection is undefined.

Please guide.