2014-11-24 61 views
0

** ** strong text如何燼如何通過價值灰燼的js與控制器進行點擊事件

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

    </div> 

    - 
    <p> 
     Selected: {{App.selectedComboBoxController.model.title}} 
</p> 

在上面,我得到正確的輸出碼傳球值控制器。 但我想傳遞一個值控制器無任何按鍵

**Here my controller.** 

App.ComboBoxController = Ember.Controller.extend({ 

}); 

回答

0

它需要的是將與當前上下文選擇的值時,控制器關聯。所以在下面的例子中,假定當前上下文是索引路由,模型返回一個對象數組。

例如

HBS

<script type="text/x-handlebars" data-template-name="index"> 
    <div> 
    {{view "select" content=model prompt="Please select a name" selectionBinding="controllers.selectedComboBox.model" optionValuePath="content.fullName" optionLabelPath="content.title" }} 
</div> 

    - 

    <p> 
     Selected: {{controllers.selectedComboBox.model.title}} 
</p> 
    </script> 

JS

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

App.IndexController = Em.ArrayController.extend({ 
    needs:["selectedComboBox"] 

}); 

App.SelectedComboBoxController = Em.ObjectController.extend({ 
    model:null 
}); 

http://emberjs.jsbin.com/jodaqumoba

+0

喜melc..how我可以得到選定的值在controller.iam不理解下面的行App.IndexController = Em.ArrayController.extend({「selectedComboBox」] });你可以顯示這個值的警報 – raj 2014-11-24 09:14:49

+0

@raj'needs'屬性用於管理控制器之間的依賴關係(文檔:http://emberjs.com/guides/controllers/dependencies-between-controllers/),通過ember服務查找(http ://emberjs.com/guides/understanding-ember/dependency-injection-and-service-lookup/)。通過在'IndexController'中添加'needs:[「selectedComboBox」]',然後ember會自動創建一個'SelectedComboBoxController'的單例,並將其與'IndexController'關聯,以便通過'controllers.selectedComboBox'屬性可以訪問它。 – melc 2014-11-24 10:01:15

+0

@raj沒有注意到你發佈的'ComboBoxController'代碼,所以這裏是使用這個控制器的同樣的例子http://jsbin.com/jidemihujo/1 – melc 2014-11-24 10:04:14