2014-11-24 27 views
0

使用下面的代碼我在餘燼中顯示組合框。更改組合框在燼中的聽衆js

{{view "select" content=model prompt="Please select a name" selectionBinding="App.selectedComboBoxController.model" optionValuePath="content.fullName" optionLabelPath="content.title" }} 

輸出 http://emberjs.jsbin.com/jodaqumoba/1/edit?html,css,js,output

我的要求是組合框改變時間,我怎麼能叫下面提交功能

App.ComboBoxRoute = Ember.Route.extend({ 

    model: function() {  
      return posts;  
    }, 
    actions: { 
     submit: function() { 
      textId = document.getElementById("emnn"); 
      textId = textId.value; 
      alert(textId); 
     } 
    } 

}); 

回答

0

可以觀察員添加到組合框值。在觀察員發送一個行動,將導致路線起泡。

Here is the working demo.

App.SelectedComboBoxController = Em.ObjectController.extend({ 
    model:null, 

    selectionChanged: function() { 
    this.send('submit', this.get('model')); 
    }.observes('model') 
}); 

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
    return [ 
     {fullName:"the full name1", title:"the title1"}, 
     {fullName:"the full name2", title:"the title2"}, 
     {fullName:"the full name3", title:"the title3"} 
    ]; 
    }, 
    actions: { 
    submit: function (item) { 
     alert(item.fullName); 
    } 
    } 
});