gpt4 book ai didi

ember.js - 在Ember数据中遍历DS.hasMany

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

我和Ember真的很挣扎。

在我的模型中,我有一个属性:
options: DS.hasMany('UserOptions', {async: false})
在链接到该模型的 View 中,我可以通过以下方式轻松访问此属性:

{{#each options AS |option|}}
something....
{{/each}}

就像魅力一样。

但是,当我尝试使用以下命令在 Controller 中访问此模型值时: this.get('model.options')我没有得到漂亮的支付选项数组,而是得到了对象模型的 Ember 模型数组,而且无法访问实际数据。

你们是否知道如何在 Controller 中访问此数据并进行处理?

谢谢!

最佳答案

this.get('model.options')将为您提供RSVP.Promise,因此您需要使用异步代码。用:

this.get('model.options').then(options => {
options.forEach(option => {
// do what you need with option
})
});

关于ember.js - 在Ember数据中遍历DS.hasMany,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44415937/

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