2014-04-19 21 views
0

作爲一個將來應用程序的自我練習,我試圖從使用localStorage的書中轉換已修改的應用程序。轉換後的應用程序將使用Parse.com數據而不是localStorage。將localStorage轉換爲Parse.com

長話短說,它不工作。我可以從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的代碼。

非常感謝您提前!

+0

我從頭開始用一個更簡單的項目,但我仍然有問題。我正在做一些根本性錯誤的事情。我會用不同的方式詢問: 當我檢索Parse對象的集合時,在我可以使用underscore.js來幫助我查看它之前,需要對該數據進行什麼操作?我可以在console.log中看到數據,但它深深嵌套。我認爲從集合中收到的數據根本不適用於View: 'render:function(){var _html = this.template(); this。$ el.html(html); this.collection.each(this.renderOne,this); return this;' Thks! – mrbranden

回答

0

我對parse.com不熟悉,但不能從parse.com中檢索數據並將其結構化爲可以用來填充backbone.collection?

+0

對不起,延遲迴復。是的,那是我正在努力的一部分:我如何適當地重組數據? – mrbranden

+0

你有可能創建一個從parse.com中檢索一些數據的jsfiddle嗎?然後我們可以看看,並嘗試使用它與骨幹。 –

+0

如果我創建了一個jsfiddle,我會給每個人訪問我的API密鑰和我的數據,對吧? – mrbranden

相關問題