Uncaught TypeError: Cannot read property 'localStorage' of undefined

允我心安 提交于 2019-12-07 18:12:42

问题


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.

来源:https://stackoverflow.com/questions/14423455/uncaught-typeerror-cannot-read-property-localstorage-of-undefined

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