有人有一个好的解决方案可以将 Parse.com 对象
存储到 Javascript
项目的 localStorage 中吗?
我遇到的问题是,当将对象转换为JSON
时,我们丢失了对象的ID。这是因为 Parse.com 对象
中的 id 未存储在属性中。
给我一些提示。
提前致谢。
更新 我的小例子
var Something = Parse.Object.extend("Something");
var something = new Something();
something.set("attribute1", "attribute1");
something.save(null, {
success: function(obj) {
something.fetch({
success: function(obj) {
console.log("object:"); console.log(obj);
console.log("json:"); console.log(JSON.stringify(obj));
},
})
},
})
这给出了这个输出:
object: appmob.js:1563
d.hasOwnProperty.f
_changing: false
_escapedAttributes: Object
_existed: true
_hasData: true
_hashedJSON: Object
_opSetQueue: Array[1]
_pending: Object
_previousAttributes: Object
_saving: false
_serverData: Object
_silent: Object
attributes: Object
changed: Object
cid: "c0"
createdAt: Mon Sep 03 2012 15:43:50 GMT+1000 (EST)
id: "e419YJmhR5"
updatedAt: Mon Sep 03 2012 15:43:50 GMT+1000 (EST)
__proto__: c
** 有 id。
json:
{"attribute1":"attribute1","attribute2":"attribute2"}
** 没有 id。
这与此 stackoverflow 问题相关 Backbone model .toJSON() doesn't render all attributes to JSON
所以我想知道将 JSON 字符串存储到本地存储中的最简单方法是什么。
最佳答案
您可能有兴趣了解更新后的 Parse 对 JS SDK 的影响:
v1.1.10 — 2012 年 11 月 13 日
Parse.Object 的扩展 JSON 序列化:在 Parse.Object 上调用 JSON.stringify() 现在将在输出中包含默认属性“objectId”、“createAt”和“updatedAt”。
关于local-storage - 简单的 Parse.com 本地存储解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12189933/