まず、Ember.js で promise を操作する方法がわかりません。ネストされている非同期モデルデータに依存するコントローラーのプロパティを呼び出したいです。
また、私のモデルは次のようになります。
+-------------+ +------------+
| Method | hasMany | Practice |
| +---------> |
| | | |
+-------------+ +------------+
|
| hasMany
+-----v------+
| Alpha |
| |
| |
+------------+
だから私はこのようなものを作成しました:
allAlphas: function() {
var self = this;
var returnValue = "nichts";
var promises = {
allAlphas: self.get('model.method').then(function(method) {
//get the practices
return method.get('practices');
}).then(function(practices) {
//get the alphaSField in EVERY practice
//the alphasField is the (hasmany 'alpha')member in practice
var alphasFields = practices.getEach('alphas');
return Ember.RSVP.all(alphasFields).then(function() {
return alphasFields;
});
}).then(function(alphasFields) {
// here: get all the alphas via promise or something
})
};
Ember.RSVP.hash(promises).then(function(results) {
// return all the alphas (of all pracitces in the method) in some way
});
}.property()
2つの問題があります(コメントですでに言及されているように):
- すべてのプラクティスですべてのアルファのように、ネストされた hasMany 非同期モデルをロードする方法。
- テンプレートなどで使用する RSVP.hash-Method のプロパティとして完全な結果を返す方法
誰でも私を助けることができますか?
2015 年 6 月 20 日編集
@Kingpin2k が示唆したように、問題をよりよく理解するために Gist を追加しました: https://gist.github.com/MarcManhart/e5c1d91e8fdfd876de37