local-storage - 简单的 Parse.com 本地存储解决方案

标签 local-storage parse-platform

有人有一个好的解决方案可以将 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/

相关文章:

android - 在 Android 中从 Parse.com 检索对象

parse-platform - 解析安卓: update ParseObject containing an array of ParseUsers throws UserCannotBeAlteredWithoutSessionError

javascript - 解析查询未获取 ParseObject 的相关 ParseUser

javascript - 刷新页面时保存用户的选择

json - 本地存储中的 TypeScript 类型序列化/反序列化

ios - 如何在 Parse.com 中使用 Sql "Select"for Swift

javascript - 解析 Javascript - 如何通过关系对象的属性进行查询

javascript - 以 Angular 4 读取和写入文件

javascript - 如何从多个本地json文件生成highcharts图表

javascript - 使用 localStorage 编辑一组对象