すべてのテストを 2 回、ドキュメントを 3 回読みましたが、Ember の使用方法を理解できていません。正しい方法を選択してください。私はかなり単純なケースだと思うものを持っています:
モデル オブジェクト (goal_type) に文字列値があり、select に双方向でバインドし、その select を goal_type フィールドの開始値にデフォルト設定します。いくつかの質問:
- モデルの最初の goal_type を選択で受け入れることができません。
- これはすべて複雑すぎるようです。オブザーバーを設定して元のコントローラーの状態を変更するよりも簡単な方法があるはずです。
助けて - 私はこれを理解しようとして夢中になっています.
Azul.goalController = Ember.Object.create({
loadGoal: 関数(データ) {
this.set('content', Azul.store.loadAll(Azul.Goal, data));
}、
newGoal: 関数() {
goal = Azul.store.createRecord(Azul.Goal, {goal_type: "type2"});
this.set('コンテンツ', ゴール);
Azul.selectedGoalTypeController.selectGoalType(goal.get('goal_type'));
}
});
Azul.selectedGoalTypeController = Ember.Object.create({
selectedGoalType: null,
selectedGoalTypeChanged: 関数() {
Azul.goalController.content.set('goal_type', this.selectedGoalType.value);
}.observes('selectedGoalType'),
selectGoalType: 関数(goal_type) {
Azul.goalTypesController.content.forEach(function(item, index, self) {
if (goal_type == item.value) {
self.set('selectedGoalType', item);
}
});
}
});
Azul.goalTypesController = Ember.ArrayController.create({
コンテンツ: [
{値: 'type1', ラベル: 'タイプ 1'},
{値: 'type2', ラベル: 'タイプ 2'}
]
});