0
모든 테스트를 두 번 읽었으며 문서를 세 번 읽었으며 여전히 Ember를 사용하는 방법을 잘 모르겠습니다. 올바른 방법을 선택하십시오. 나는 매우 간단한 경우라고 생각한다.Ember.Select 기본값을 올바르게 설정하지 않음
나는 목표 객체 유형 (goal_type)에 문자열 값을 가지고 있는데,이 객체 값은 select에 양방향으로 바인딩하고 select는 goal_type 필드의 시작 값을 기본값으로 갖기를 원한다. 몇 가지 질문 :
- 모델의 초기 goal_type을 수락 할 선택을받을 수 없습니다.
- 이 모든 것이 너무 복잡해 보입니다. 관찰자를 설정하여 원래 컨트롤러의 상태를 수정하는 것보다 쉬운 방법이 있어야합니다.
도움말 -이 문제를 파악하는 데 미쳐 가고 있습니다.
Azul.goalController = Ember.Object.create({ loadGoal: function(data) { this.set('content', Azul.store.loadAll(Azul.Goal, data)); }, newGoal: function() { goal = Azul.store.createRecord(Azul.Goal, {goal_type: "type2"}); this.set('content', goal); Azul.selectedGoalTypeController.selectGoalType(goal.get('goal_type')); } }); Azul.selectedGoalTypeController = Ember.Object.create({ selectedGoalType: null, selectedGoalTypeChanged: function() { Azul.goalController.content.set('goal_type', this.selectedGoalType.value); }.observes('selectedGoalType'), selectGoalType: function(goal_type) { Azul.goalTypesController.content.forEach(function(item, index, self) { if (goal_type == item.value) { self.set('selectedGoalType', item); } }); } }); Azul.goalTypesController = Ember.ArrayController.create({ content: [ {value: 'type1', label: 'Type 1'}, {value: 'type2', label: 'Type 2'} ] });
샘플을 이해 합니다만, 모델의 필드를 값에 바인딩하는 것이 좋습니다. 선택하고 모델의 필드 값을 선택에 대한 기본값으로 설정합니다. 나는 아직 그것을하기위한 멍청이 방법을 이해하고 있는지 잘 모르겠다. – outside2344
바이올린을 업데이트하여 조금 더 도움이되는지 확인하십시오 ... – Luan