gpt4 book ai didi

javascript - Ember js 等待 Controller this.get 请求/休息适配器滞后

转载 作者:行者123 更新时间:2023-11-29 14:53:13 25 4
gpt4 key购买 nike

我试图在其各自的 Controller 中访问我的模型的内容,但它最初返回一个具有未定义属性的 promise ,然后在第二次或第三次访问时返回值。

会不会是从 REST 适配器中检索数据有延迟?

还尝试在 Controller 中的请求中使用“.then()”是行不通的,因为我认为它仅在路由中使用。

App.EquipmentsController = Ember.ArrayController.extend({
getContentForMapping: function() {
console.log(this.get('model').objectAt(1).get('contractor.name'));
//returns undefined first time
}
});

奇怪的是,当我在循环中从模板 View 访问模型的属性时,它会立即返回它们。

{{#each equipment in model}}
<p>{{equipment.contractor.name}}</p>
{{/each}}

下面是我如何设置路线。它正在获取与特定站点相关的设备列表:

App.EquipmentsRoute = Ember.Route.extend({
model: function(){
//Get the model for the selected site and grab its equipment list.
return this.modelFor('site').get('equipment');
},
//Set the model we just grabbed above as the model to use in the controller
setupController: function(controller, model) {
controller.set('model', model);
}
});

最佳答案

更改我们的 API 端点以支持侧载似乎已经解决了我们在发出 this.get('model') 请求时遇到的延迟。

在 ember 指南中有一小部分涵盖了这一点:http://emberjs.com/guides/models/the-rest-adapter/

关于javascript - Ember js 等待 Controller this.get 请求/休息适配器滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21976717/

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