Ember.js 在同一路由上加载多个模型会从服务器返回良好的json,但模型为空
我想在同一路线上加载多个模型。现在,我正在使用setupController进行此操作。基本上,我调用服务器来填充对话、子用户和当前子用户的模型 子用户返回正确加载到存储中的json数组 对currentsubuser的调用从服务器返回良好的json(如下所示:),但与子用户不同,它没有正确加载到存储中(如下所示:) 正如您所看到的,我使用与加载子用户和currentuser完全相同的代码,但是我不知道为什么不能将currentsubuser中的数据加载到存储中 currentsubuser和subuser的模型是相同的,它们包含完全相同的属性(仅供参考,我尝试将currentsubuser侧向加载到与子用户相同的有效负载中,但没有成功,因此我创建了自己相同的模型): 路线:Ember.js 在同一路由上加载多个模型会从服务器返回良好的json,但模型为空,ember.js,ember-data,Ember.js,Ember Data,我想在同一路线上加载多个模型。现在,我正在使用setupController进行此操作。基本上,我调用服务器来填充对话、子用户和当前子用户的模型 子用户返回正确加载到存储中的json数组 对currentsubuser的调用从服务器返回良好的json(如下所示:),但与子用户不同,它没有正确加载到存储中(如下所示:) 正如您所看到的,我使用与加载子用户和currentuser完全相同的代码,但是我不知道为什么不能将currentsubuser中的数据加载到存储中 currentsubuser和s
App.ConversationsRoute = Ember.Route.extend({
subusers: null,
currentsubuser: null,
model: function(params){
return this.store.find('conversation', { status : params.status});
},
setupController: function(controller, model){
this._super(controller, model);
if(!this.get('subusers') && !this.get('currentsubuser'))
{
this.set('subusers', this.store.findAll('subuser'));
this.set('currentsubuser', this.store.find('currentsubuser'));
}
this.controllerFor('subusers').set('content', this.get('subuser'));
this.controllerFor('currentsubuser').set('content', this.get('currentsubuser'));
},
queryParams: {
status: {
refreshModel: true
}
}
});
路由器:
App.Router.map(function(){
//Routing list to raw namespace path
this.resource('conversations', { path : '/' }, function() {
this.resource('conversation', { path : '/:conversation_id'});
});
});
调用
this.store.find('currentsubuser')
需要将currentsubusers
作为根的json数组(而不是currentsubuser
)。这就是响应没有加载到存储中的原因。好的,我发现了一个解决方案,我确信这个解决方案令人困惑,但这里是:我重写了我当前的json生成器,让它返回一个单个对象的数组,而不是使用单个对象作为json的根。现在它显示在我的数据中。
App.Router.map(function(){
//Routing list to raw namespace path
this.resource('conversations', { path : '/' }, function() {
this.resource('conversation', { path : '/:conversation_id'});
});
});