我嘗試了幾個版本/嘗試創建並返回RSVP.Promise
作爲模板的參數。解決承諾不會顯示模板中的數據
所有的console.log都給出合理的值,所以承諾分辨率爲。 問題我有(這也是問題)是如何將解析值返回給我的模板。
這裏是我試過的版本:我測試如同我所有的測試,以便
// in controller.js
testA: Ember.computed('sessionAccount.account.id', function() {
let _this = this;
let promise = new Ember.RSVP.Promise(function(resolve, reject) {
_this.get('store').findAll('accounts2workgroup').then(function(a2ws) {
let workgroups = [];
a2ws.forEach(function(a2w){
if(a2w.get('rights')>1) {
workgroups.push(a2w.get('workgroup'));
}
});
console.log(workgroups);
_this.set('wgAsAdmin', workgroups); // this works
resolve(Ember.A(workgroups)); //=> [Object] in rendered template
// return workgroups; // no, not that way
});
});
promise.then(function(data) {
console.log('did resolve');
console.log(data);
})
return promise;
}).property('sessionAccount.account.id'),
testB: Ember.computed('sessionAccount.account.id', function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
let workgroups = Ember.ArrayProxy.create([{'label': 'TestB Label'}]);
resolve(workgroups);
});
}),
testC: Ember.computed(function() {
return this.store.findAll('artists2workgroup').then(function(a2ws) {
let workgroups = [];
a2ws.forEach(function(a2w){
if(a2w.get('rights')>1) {
workgroups.push(a2w.get('workgroup'));
}
});
console.log(workgroups);
return workgroups; //=> [Object] in rendered
});
}),
testD: Ember.computed(function() {
return this.store.findAll('workgroup'); // this of course works, but that's not what I want...
}),
在我的模板
:
<h4>TestB</h4>
{{#each testB as |wg|}}
{{wg}}<br>
{{wg.label}}<br>
{{/each}}
testB: {{testB}}<br>
testB.length: {{testB.length}}<br>
和所有(但最後TESTD明顯)渲染
TESTB
TESTB:[對象的對象]
testB.length:
,雖然我希望/希望他們表現出
TESTB
< DS.PromiseObject:ember1117 >
BB-促進
TESTB:< DS.PromiseObject :ember1117 >
testB.length:1
我知道有解決方法(我可以在解決f.e.時設置另一個屬性),但想要以正確的方式做,並學習如何做到這一點。 我知道,這些例子沒有太大意義。這只是基本的功能,一旦我運行,它會得到增強。
非常感謝這個全面的答案!我學到了很多東西! (最引人注目的事實是,廟會並不承諾) – Jeff