Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 将localStorage转换为Parse.com_Backbone.js_Parse Platform_Marionette_Backbone Views - Fatal编程技术网

Backbone.js 将localStorage转换为Parse.com

Backbone.js 将localStorage转换为Parse.com,backbone.js,parse-platform,marionette,backbone-views,Backbone.js,Parse Platform,Marionette,Backbone Views,作为未来应用程序的练习,我正在尝试从使用localStorage的书中转换修改后的应用程序。转换后的应用程序将使用Parse.com数据而不是localStorage 长话短说,它不起作用。我可以从Parse.com获取集合,但视图不会呈现它。我没有得到任何错误,它只是不显示数据。经过大量调试后,我注意到localStorage版本和Parse.com版本中返回的数组之间存在差异: Array[1] 0: child _byCid: Object _byId: Object _callbacks

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

长话短说,它不起作用。我可以从Parse.com获取集合,但视图不会呈现它。我没有得到任何错误,它只是不显示数据。经过大量调试后,我注意到localStorage版本和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
本地存储:

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__
Entities.CharacterCollection = Parse.Collection.extend({
   model: Entities.Character
  });
但是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”。。。“主干.集合”改为“解析.集合”。然后,我从Parse.Collection中删除了“url”参数,并指定了模型:

本地存储

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

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__
Entities.CharacterCollection = Parse.Collection.extend({
   model: Entities.Character
  });
我在这里真是不知所措。我觉得问题很简单,但我只是错过了。 我正在使用Parse.com JavaScript API,我的代码也在使用木偶


提前非常感谢

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

很抱歉延迟回复。是的,这也是我正在努力解决的问题的一部分:如何适当地重新构造数据?您是否可以创建一个JSFIDLE来从parse.com检索一些数据?然后我们可以看一看并尝试将其用于主干网。如果我创建了一个JSFIDLE,我会让每个人都可以访问我的API密钥和数据,对吗?如果是这样,你不应该这样做。但是,您可以提供服务器响应作为一个例子。我从头开始使用一个更简单的项目,但仍然存在问题。我在做一些根本错误的事情。我将以另一种方式提问:当我检索一组解析对象时,在使用下划线.js帮助我查看数据之前,是否需要对该数据执行任何操作?我可以在console.log中看到数据,但它嵌套得很深。我认为我从集合中收到的数据根本无法与视图一起工作:
render:function(){var html=this.template();this.$el.html(html);this.collection.each(this.renderOne,this);return this;
Thks!