2012-05-21 5 views
2

다음은 값이있는 드롭 다운의 기본 스 니펫입니다.Ember.js 드롭 다운 메뉴에서 기본적으로 옵션을 선택하십시오.

App.selectedOption.set("option","1"); 

하지만 기본값 인 onload로 선택한 드롭 다운이 표시되지 않습니다. 여기에서 문제가 될 수있는 것은 무엇입니까? 선택 바인딩

니핏 엠버 드롭 대

<script type="text/x-handlebars"> 
    {{#view App.SortSampleView }} 
     {{view Ember.Select 
      contentBinding="App.viewSampleController" 
      selectionBinding="App.selectedOption.option" 
      optionLabelPath="content.name" 
      optionValuePath="content.id" class="dropdown" 
     prompt="Select..." }} 
    {{/view}}  
</script> 

니펫 :

App.selectedOption= Ember.Object.create({option:null}); 

답변

3

이것은 문제 추적기에 #482을 참조 알려진 문제이다. 특정 개체를 selected으로 설정해야하는 대신 valuePath을 설정하여 선택한 옵션을 설정하는 것이 지원되지 않는다고 설명합니다. http://jsfiddle.net/pangratz666/NgXpF/ 참조 :

핸들 바을 :

<script type="text/x-handlebars"> 
     {{view Ember.Select 
      contentBinding="App.viewSampleController" 
      selectionBinding="App.selectedOptionController.option" 
      optionLabelPath="content.name" 
      optionValuePath="content.id" class="dropdown" 
     prompt="Select..." }} 
</script>​ 

자바 스크립트을 : 솔루션보다도 시도

App.viewSampleController = Ember.ArrayProxy.create({ 
    content: [], 
    addObject: function(id, name){ 
     this.pushObject(Ember.Object.create({ 
      id: id, 
      name: name 
     })); 
    } 
}); 

App.selectedOptionController = Ember.Object.create({ 
    option: null 
}); 

App.viewSampleController.addObject(1, 'first'); 
App.viewSampleController.addObject(2, 'second'); 
App.viewSampleController.addObject(3, 'third'); 

var second = App.viewSampleController.objectAt(1); 
App.selectedOptionController.set('option', second); 
+0

작동하지 않습니다! 다른 방법으로 제안 해주세요. – user1338121

+0

JSFiddle을 보았습니까? 이것은 나를 위해 작동합니다. 작동하지 않는 코드로 피들을 제공 할 수 있습니까? – pangratz

+0

예 .. 해결책에 대한 감사했습니다! – user1338121

관련 문제