【发布时间】:2013-04-30 17:26:10
【问题描述】:
我正在使用 jeromegn localstorage 插件https://github.com/jeromegn/backbone.localStorage。
model.set(data);
model.save();
console.log(model) // I am getting the json
console.log(JSON.stringify(localStorage['Session'])); // I am getting the model's Id
我正在尝试保存一个模型,但它似乎只保存了我的模型的 ID?
【问题讨论】:
-
您的模型有 ID 吗?我不知道它是否在最近的版本中发生了变化,但过去我在尝试自己保存模型时需要添加
defaults: { id: 1 }(不是通过集合)。 -
它确实有一个 ID,我添加了默认值:{id: 1} 并且没有工作。
-
我正在跟踪 localstorage 并且能够看到有记录。 localStorage['Session'] // 模型的 id localStorage['Session-"model's id"'] // 保存的模型是默认行为吗?