【问题标题】:How to access value of Ember Select view from controller?如何从控制器访问 Ember Select 视图的值?
【发布时间】:2013-05-30 10:48:30
【问题描述】:

我正在构建一个简单的表单,它有几个文本框和一个选择下拉菜单,它使用其他对象的列表作为数据。

到目前为止,我已经完成了所有工作,所以当用户点击提交时,文本表单值会被抓取并创建一个新对象。

我遇到的问题是我无法访问我的选择视图的值。

{{view Ember.Select
       contentBinding="courses"
       optionLabelPath="content.name"
       optionValuePath="content.id"
       selectionBinding="SD.StudentAddController.newCourse"}}

我已经尝试了所有我能想到的方法,但不知道如何在我的控制器中获取选择字段的值。

我访问所有其他文本字段(因为它们绑定到我的控制器的属性):

this.get('<fieldname>');

我无法让选择视图绑定到控制器的属性“newCourse”...有什么想法吗?

【问题讨论】:

    标签: data-binding ember.js


    【解决方案1】:

    我错误地引用了控制器来绑定我的 newCourse 值。

    我将“SD.StudentAddController.newCourse”更改为“controller.newCourse”,它正在工作。

    所以最终选择视图hbs代码是:

    {{view Ember.Select
           contentBinding="courses"
           optionLabelPath="content.name"
           optionValuePath="content.id"
           selectionBinding="controller.newCourse"}}
    

    【讨论】:

      【解决方案2】:

      Ember Select 的 selectBinding 绑定选中的 Object ...

      http://jsbin.com/uxojek/3/edit

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-24
        • 1970-01-01
        • 1970-01-01
        • 2013-01-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多