【问题标题】:get multiple dropdown values using emberjs使用 emberjs 获取多个下拉值
【发布时间】:2014-07-06 15:54:07
【问题描述】:

我无法使用 emberjs 从下拉框中检索值。实际上,如果我使用单个选择框,我可以检索该值,但是如果我选择第二个下拉列表,那么第一个下拉框会被刷新。 所以在我的代码中,我使用了 3 个下拉框,如果我选择第 2 个或第 3 个下拉框,之前的下拉列表将被刷新。 这是我的html代码:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Registration</title>


</head>
<body>

  <!-- ... Ember.js and other javascript dependencies ... -->   
  <script type="text/x-handlebars" data-template-name="">
  <form>
  Currency {{view Ember.Select content=name optionValuePath="content.value" value=content.value optionLabelPath="content.value" selectionBinding=currency}}
  Fuel Economy {{view Ember.Select content=name1 optionValuePath="content.value" value=content.value optionLabelPath="content.value" selectionBinding=fuel}}
  Date_Format {{view Ember.Select content=name2 optionValuePath="content.value" value=content.value optionLabelPath="content.value" selectionBinding=dateval}}


    <input type="button" {{action 'check' 77}} value="Hit Me" />
</form>
  </script>

  <script src="js/libs/jquery-1.9.1.js"></script>
  <script src="js/libs/handlebars-v1.3.0.js"></script>
  <script src="js/libs/ember.js"></script>
  <script src="js/libs/ember-data.js"></script>

  <script src="js/select.js"></script>


</body>
</html>

这是我的 JS 代码:

window.Format = Ember.Application.create();
Format.ApplicationController = Ember.ArrayController.extend({

currency : null, 
fuel : null, 
dateval : null,                                                     
name: [{value:"USD"}, {value:"INR"}],
name1: [{value:"Kmph"},{value: "Mph"}],
name2: [{value:"dd/mm/yyyy"},{value: "mm/dd/yyyy"}],
actions: {
    check: function() {
        var currency = this.get("currency.value");
        var fuel = this.get("fuel.value");
        var dateval = this.get("dateval.value");

    }
}

});

【问题讨论】:

    标签: javascript html ember.js handlebars.js


    【解决方案1】:

    您需要将选择框的值绑定到控制器中的属性。

    Currency {{view Ember.Select 
      content=name 
      optionValuePath="content.value"
      optionLabelPath="content.value"
      valueBinding=currency}}
    

    然后你可以直接访问属性为this.get('currency');的值

    Here is a working bin.

    【讨论】:

    • 太棒了..终于为我工作了,非常感谢。
    • 很高兴为您提供帮助。请将此作为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2021-12-21
    • 2012-07-27
    相关资源
    最近更新 更多