Backbone localstorage: Cannot read property 'D

2019-07-18 04:27发布

I am trying to make a backbone application work with the localstorage plugin. I included the library after the backbone library.

I added the following line to my collection:

window.ProductCollection = Backbone.Collection.extend({
    model:Product,
    localStorage: new Backbone.LocalStorage("ProductCollection")
});

I keep getting the following error from backbone.localstorage.js: Cannot read property 'Deferred' of undefined

Is there anything i forgot to do in the implementation of the library? Documentation says you only need to add the localstorage to your collection.

http://jsfiddle.net/4uDGb/

1条回答
叼着烟拽天下
2楼-- · 2019-07-18 05:19

I fixed your fiddle, and despite what I said in the other thread, it was a bit of a faff! Your error was to do with the order you were importing the libraries (Backbone depends on Underscore and jQuery, Backbone.LocalStorage relies on Backbone). The most reliable way of getting the order right in the fiddle was to add the CDN links in order to the external resources tab.

Your code is running for me in Chrome with no errors and I can inspect the data saved to local storage using the resources tab in dev tools. I would suggest checking you're using all the latest versions of the various libraries in your local build.

查看更多
登录 后发表回答