我有 2 个实例。我的本地操作系统为 Win7,服务器实例的操作系统为 Linux。
我正在获取 JSON 数据并使用以下代码将其设置为模型。
var RModel = Backbone.Model.extend({
idAttribute: 'name',
parse: function (response) {
return {
'name': response.name,
'title': response.title,
'description': response.description,
'parameters': new ParamsList(response.parameters)
};
}
});
that.model = new RModel();
that.model.url = "url/" + '?limited=false';
that.model.fetch({
cache: false
}).done(function() {
that.headerTemplate = that.headerTemplateEdit;
that.bodyTemplate = that.bodyTemplateEdit;
that.footerTemplate = footerTemplate;
that.load({});
});
在我的本地实例中,控制台中执行以下代码的结果。
this.model
child
_changing:false
_pending:false
_previousAttributes:Object
attributes:Object
changed:Object
cid:"c217"
id:"testUndefinedParam"
url:"/url?limited=false"
__proto__:
Backbone.Model
在服务器实例中
this.model
i
_changing: false
_pending: false
_previousAttributes: Object
attributes: Object
changed: Object
cid: "c25920"
id: "testDateError2"
url: "/url?limited=false"
__proto__: t.Model
如果有人遇到此问题,请展示某种正确检索 JSON 数据的方法。
最佳答案
我的猜测是,您的服务器中的代码已被处理(minify/uglify),而您本地中的代码则没有。因此,处理器只是将 child
重命名为 i
,将 Backbone
重命名为 t
等。您应该关心实际的差异控制台输出的数据而不是构造函数名称。据我所知,没有标准,并且不同浏览器之间可能有所不同
关于javascript - Backbone.js fetch() 在服务器实例中返回对象而不是子对象,但在本地实例中检索子对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674932/