骨干本地存储" undefined是不是一个函数" [英] Backbone Local Storage "undefined is not a function"
问题描述
我使用 Backbone.LocalStorage
http://jsfiddle.net/jiewmeng/grhz9/3/
I am using Backbone.LocalStorage
: http://jsfiddle.net/jiewmeng/grhz9/3/
$(function() {
console.log(Backbone.LocalStorage); // undefined!!
var Todo = Backbone.Model.extend({});
var Todos = Backbone.Collection.extend({
model: Todo,
localStorage: new Backbone.LocalStorage("todos")
});
});
第1 的console.log()
给未定义
。再就是在 localStorage的一个错误:...
行
未捕获类型错误:未定义不是一个函数
Uncaught TypeError: undefined is not a function
因为 Backbone.LocalStorage
预计为未定义
但是为什么呢?
Expected since Backbone.LocalStorage
is undefined
but why?
推荐答案
的 backbone.localStorage-min.js
你加载:
<一个href=\"http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js\">http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js
看起来是过时的,并没有在所有的定义 Backbone.LocalStorage
。 backbone.localStorage-min.js的版本
您使用的是定义 window.Store
,而不是 Backbone.LocalStorage
。如果您切换到( http://jsfiddle.net/ambiguous/grhz9/5/ ):
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")
});
那么你可以得到过去构建托多斯
集合。我不知道有多好,当你真正尝试,虽然用它的东西会工作。 太阳2011年8月14日9点53分55秒-0400是pretty永远得多,以前,在上网的时候,这样的版本是相当古老的。
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.
如果你从GitHub切换到最新版本:
If you switch to the latest version from Github:
<一个href=\"https://raw.github.com/jeromegn/Backbone.localStorage/master/backbone.localStorage-min.js\">https://raw.github.com/jeromegn/Backbone.localStorage/master/backbone.localStorage-min.js
你会看到有在JavaScript中的一些差异,一切都将开始工作,当您使用新Backbone.LocalStorage('待办事项')
:
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/
这篇关于骨干本地存储&QUOT; undefined是不是一个函数&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!