Backbone Local Storage “undefined is not a function”

前端 未结 2 1827
一生所求
一生所求 2021-01-03 00:50

I am using Backbone.LocalStorage: http://jsfiddle.net/jiewmeng/grhz9/3/

$(function() {
    console.log(Backbone.LocalStorage); // undefined!         


        
相关标签:
2条回答
  • 2021-01-03 01:27

    The backbone.localStorage-min.js you're loading:

    http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js

    looks like it is out of date and it doesn't define Backbone.LocalStorage at all. The version of backbone.localStorage-min.js that you are using defines window.Store rather than Backbone.LocalStorage. If you switch to that (http://jsfiddle.net/ambiguous/grhz9/5/):

    var Todos = Backbone.Collection.extend({
        model: Todo,
        localStorage: new Store("todos")
    });
    

    then you can get past building your Todos collection. I don't know how well things will work when you actually try to use it though. "Sun Aug 14 2011 09:53:55 -0400" is pretty much forever-ago in internet time so that version is rather antique.

    If you switch to the latest version from Github:

    https://raw.github.com/jeromegn/Backbone.localStorage/master/backbone.localStorage-min.js

    you'll see that there are a few differences in the JavaScript and everything will start working when you use new Backbone.LocalStorage('todos'):

    http://jsfiddle.net/ambiguous/grhz9/4/

    0 讨论(0)
  • 2021-01-03 01:36

    The other answer is correct - 1.0 is out of date.

    I've updated backbone.localstorage to the latest version:

    http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.1.0/backbone.localStorage-min.js (production)

    http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.1.0/backbone.localStorage.js (dev)

    Hope that helps!

    0 讨论(0)
提交回复
热议问题