如果这个问题太愚蠢,请原谅我。我自己正在研究 Ember.js,但我遇到了一个问题,我需要动态设置文本框的值,我现在不知道该怎么做我正在使用 jquery通过使用来克服这个错误$("#results")[0].value = data;
,我知道这不是正确的方法我如何在 Ember,js 中做同样的事情
我的当前代码如下
App = Em.Application.create();
App.BaseCurrency = Em.Object.extend({
id: null,
name: null
});
App.DestCurrency = Em.Object.extend({
id: null,
name: null
});
App.BaseSelector = Em.ArrayController.extend({
content: [
App.BaseCurrency.create({ id: "INR", name:" Indian Rupee (INR)" }),
App.BaseCurrency.create({ id: "USD", name: "US Dollar (USD)" })
]
});
App.baseSelector = App.BaseSelector.create();
App.DestSelector = Em.ArrayController.extend({
content: [
App.DestCurrency.create({ id: "INR", name: " Indian Rupee (INR)" }),
App.DestCurrency.create({ id: "USD", name: "US Dollar (USD)" })
]
});
App.destSelector = App.DestSelector.create();
App.ConvertCurrency = Em.ObjectController.extend({
content: [],
amount:0,
baseCur: null,
destcur: null,
result: 0,
convert: function () {
var amount = this.get('amount');
var from = this.get('baseCur');
var to = this.get('destCur');
$.ajax({
type: "POST",
url: "Home/ConvertCurenncy",
data: "{amount:" + amount + ",from:'" + from + "',to:'" + to + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#results")[0].value = data;
}
});
}
});
App.convertCurrency = App.ConvertCurrency.create();
和 html
<script type="text/x-handlebars">
AMOUNT : {{view Ember.TextField valueBinding="App.convertCurrency.amount"}}
BASE : {{view Ember.Select contentBinding="App.baseSelector" optionLabelPath="content.name" optionValuePath="content.id" valueBinding="App.convertCurrency.baseCur" }}
DEST : {{view Ember.Select contentBinding="App.destSelector" optionLabelPath="content.name" optionValuePath="content.id" valueBinding="App.convertCurrency.destCur" }}
<button id="btnConvert"{{action "convert" target="App.convertCurrency"}}>convert</button>
RESULT :<input type="text" readonly=true id="results" />
</script>