Ember Ember.select get selected value

前端 未结 1 1002
一整个雨季
一整个雨季 2021-01-19 09:18

I have a simple Ember application where I have an input box, two select boxes and a button. I can access the value of the input box in the method \"doSearch\", but not the v

相关标签:
1条回答
  • 2021-01-19 09:49

    Extend your ApplicationController with two new variables to hold the selected values:

    App.ApplicationController = Ember.ArrayController.extend({
      selectedContentType: null,
      selectedDate: null,
      ...
    });
    

    and use the selectionBinding property of the Ember.Select class to bind to those variables

    <span class="filter">Content Type:
      {{view Ember.Select
        content=selectContentType
        optionValuePath="content.value"
        optionLabelPath="content.label"
        selectionBinding=selectedContentType}}
    </span>
    <span class="filter">Date:
      {{view Ember.Select
        content=selectDate
        optionValuePath="content.value"
        optionLabelPath="content.label"
        selectionBinding=selectedDate}}
    </span>
    

    then you can later access them easily with:

    App.ApplicationController = Ember.ArrayController.extend({
      selectedContentType: null,
      selectedDate: null,
      ...
      actions: {
        doSearch: function () {
          var selectedDate = this.get('selectedDate.value');
          console.log( selectedDate );
    
          var selectedType = this.get('selectedContentType.value');
          console.log( selectedType );
        }
      }
    });
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题