将localStorage转换为Parse.com

时间:2014-04-19 14:21:06

标签: backbone.js parse-platform marionette backbone-views

作为对未来应用程序的练习,我试图从使用localStorage的书中转换修改后的应用程序。转换后的应用程序将使用Parse.com数据而不是localStorage。

长话短说,它不起作用。我可以从Parse.com获取该集合,但View不会呈现它。我没有得到任何错误,它只是不显示数据。经过大量的调试后,我注意到localStorage版本中返回的数组与Parse.com版本之间存在差异:

localStorage的:

Array[1]
0: child
[object Object]: (...)
get [object Object]: function () {
set [object Object]: function (newval) {
[object Object],[object Object]: (...)
get [object Object],[object Object]: function () {
set [object Object],[object Object]: function (newval) {
[object Object],[object Object],[object Object]: (...)
get [object Object],[object Object],[object Object]: function () {
set [object Object],[object Object],[object Object]: function (newval) {
__backboneDebugger__appComponentInfo: window.__backboneAgent.AppComponentInfo
__backboneDebugger__isInstancePatched: true
_byId: Object
_events: Object
initialize: (...)
length: 3
models: (...)
get models: function () {
set models: function (newval) {
sync: function () {
trigger: function (name) {
url: (...)
get url: function () {
set url: function (newval) {
watchers: Object
__proto__: Surrogate
length: 1
__proto__

但是Parse.com版本:

Array[1]
0: child
_byCid: Object
_byId: Object
_callbacks: Object
length: 2
models: Array[2]
0: child
_callbacks: Object
_escapedAttributes: Object
_hasData: true
_hashedJSON: Object
_opSetQueue: Array[1]
_pending: Object
_previousAttributes: Object
_serverData: Object
_silent: Object
attributes: Object
changed: Object
cid: "c1"
collection: child
createdAt: Wed Apr 16 2014 20:23:50 GMT-0400 (EDT)
id: "qYM3ORQ6po"
updatedAt: Fri Apr 18 2014 18:21:12 GMT-0400 (EDT)
__proto__: EmptyConstructor
1: child
_callbacks: Object
_escapedAttributes: Object
_hasData: true
_hashedJSON: Object
_opSetQueue: Array[1]
_pending: Object
_previousAttributes: Object
_serverData: Object
_silent: Object
attributes: Object
changed: Object
cid: "c2"
collection: child
createdAt: Wed Apr 16 2014 22:10:07 GMT-0400 (EDT)
id: "SpCYqDPZdZ"
updatedAt: Wed Apr 16 2014 22:27:16 GMT-0400 (EDT)
__proto__: EmptyConstructor
length: 2
__proto__: Array[0]
__proto__: EmptyConstructor
length: 1

localStorage渲染正确,但Parse.com根本不渲染。正确的数据在Parse.com数组中...所以它肯定是从Parse.com中检索它的。但是,正如您所看到的,数据的格式非常不同。

我怀疑这是我的问题所在。

代码之间的主要区别是“Backbone.model”更改为“Parse.Object”...并且“Backbone.Collection”更改为“Parse.Collection”。然后我从Parse.Collection中删除了“url”参数并指定了模型:

localStorage的

Entities.CharacterCollection = Backbone.Collection.extend({
    url: "characters",
    model: Entities.Character
  });

Parse.com:

Entities.CharacterCollection = Parse.Collection.extend({
   model: Entities.Character
  });

我真的很茫然。我觉得问题很简单,但我只是错过了它。 我正在使用Parse.com JavaScript API,我的代码也使用Marionette。

非常感谢你!

1 个答案:

答案 0 :(得分:0)

我对parse.com并不熟悉,但您是否能够从parse.com检索数据并将其结构化,以便您可以使用它来填充backbone.collection?