gpt4 book ai didi

ember.js - 升级到ember-data beta2时出错

转载 作者:行者123 更新时间:2023-12-02 06:11:19 25 4
gpt4 key购买 nike

尝试通过一个 Restful api加载一组记录时遇到此错误。它适用于ember-model,但是当我切换到ember-data(测试版2)和ember.js(1.0)时,出现此错误。

断言失败:找不到“0”的模型

App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://localhost:8080',
namespace: 'api'
});


App.Router.map(function() {
this.resource('about');
this.resource('pages', function() {
this.resource('page', { path: ':page_id' });
});
this.resource('login');
});

App.AuthenticatedRoute = Ember.Route.extend({
actions: {
error: function(reason, transition) {
if (reason.status == 403) {
alert('You must login');
this.transitionTo('login');
}
else {
//alert('non 403 error:'+reason.status);
this.transitionTo('login');
}
}
}
});


App.PagesRoute = Ember.Route.extend({
model: function() {
return this.store.find('page');
}
});

App.PageRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('page', params.page_id);
}
});

App.Page = DS.Model.extend({
user: DS.attr('string'),
slug: DS.attr('string'),
zcontent: DS.attr(),
title: DS.attr('string'),
create_time: DS.attr('date'),
update_time: DS.attr('date')
});

这是后端返回的内容:
{
"pages": [
{
"update_time": "2013-01-14 19:59:35.744855",
"title": "",
"id": 38,
"create_time": "2012-08-04 15:08:16",
"user": "robert-jones",
"slug": "orange"
},
{
"update_time": "2013-01-14 19:59:35.899830",
"title": "",
"id": 47,
"create_time": "2012-08-03 10:04:07",
"user": "robert-jones",
"slug": "REVIEWStheraputics"
},
{
"update_time": "2012-12-18 07:16:13.656509",
"title": "'Notes on Temperature Heat Map'",
"id": 17,
"create_time": "2012-12-18 07:14:48.118119",
"user": "robert-jones",
"slug": "50612c27b94ca650"
},
{
"update_time": "2012-12-12 19:48:08.079021",
"title": "'Notes on Dyanmic Heat Map'",
"id": 8,
"create_time": "2012-12-12 19:48:08.013336",
"user": "robert-jones",
"slug": "c5642b4c14d901cf"
}
]
}

最佳答案

在服务器刚返回原始数组而不是带有根元素的对象时,我就遇到过这种情况。也就是说,代替此:

{pages : [...]}

我不小心返回了这个:
[...]

没有JSBin很难看。

关于ember.js - 升级到ember-data beta2时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18855706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com