2017-08-14 83 views
0

在我的路由器我有代碼​​灰燼迭代通過一個承諾/ store.findAll返回值

我的模型user.js的將是name: DS.attr('string'), userName: DS.attr('string'), company: DS.attr('string')

在我的海市蜃樓夾具我已經User對象定義爲[{'name':'smith','userName':'smith123'},{'name':'james','userName':'james222'}

而在我的路由器上,當我做​​我想遍歷users並手動爲每個用戶添加company。但我無法找到路由器js文件中訪問用戶對象的方式。

同樣的對象我可以在.hbs文件中迭代。但無法找到在路由器js文件中迭代它的方式。你能否讓我知道如何做到這一點。

+0

你看過[燼指南](https://guides.emberjs.com/v2.14.0/)?它們涵蓋了所有基礎知識。 –

回答

0

findAll方法(和findRecord)也返回promise,而不是可迭代的對象。您可以在承諾解決後迭代用戶。要做到這一點,你應該使用then方法:

this.store.findAll('user') 
    .then(users => { 
    /*Iterate here*/ 
    }) 
    .catch(error => { 
    /*Do something to inform user about network/server/request error here*/ 
    });