0

すべてのテストを 2 回、ドキュメントを 3 回読みましたが、Ember の使用方法を理解できていません。正しい方法を選択してください。私はかなり単純なケースだと思うものを持っています:

モデル オブジェクト (goal_type) に文字列値があり、select に双方向でバインドし、その select を goal_type フィールドの開始値にデフォルト設定します。いくつかの質問:

  1. モデルの最初の goal_type を選択で受け入れることができません。
  2. これはすべて複雑すぎるようです。オブザーバーを設定して元のコントローラーの状態を変更するよりも簡単な方法があるはずです。

助けて - 私はこれを理解しようとして夢中になっています.

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'}
        ]
    });
4

1 に答える 1

1

値ではなく、選択オプションにバインドされたオブジェクトに値を設定する必要があります。ここ:

Azul.selectedGoalTypeController.selectGoalType(goal.get('goal_type'));

ただ行う:

Azul.selectedGoalTypeController.set('selectedGoalType', goal);

ところで、あなたの質問は少し混乱しているように見えました。誤解していたらごめんなさい。Select の使用方法の簡単なサンプルを作成しました。フィドルは次のとおりです: http://jsfiddle.net/Qpkz5/300/

于 2012-04-04T19:22:59.613 に答える