我有一个要传递给 ng-options 的对象数组,该数组包含下一个模式中的货币对象:
[{
"cur_iso": "ILS",
"cur_symbol": "\u20aa",
"cur_name_he": "\u05e9\u05e7\u05dc",
"cur_rate_in_nis": "1.0000",
}, {
"cur_iso": "USD",
"cur_symbol": "$",
"cur_name_he": "\u05d3\u05d5\u05dc\u05e8",
"cur_rate_in_nis": "3.8580"
}]
我正在使用ng-options从这个数组中进行选择。
<select ng-model="bindCurrencyModel" ng-init="bindCurrencyModel='ILS'"
ng-options="currency.cur_iso as currency.cur_symbol+' '+currency.cur_name_he for currency in currencies track by currency.cur_iso"
ng-change="setCurrency(currency)">
</select>
当用户更改选择时,我想更新 2 个字段:
使用值和值的bindCurrencyModel。cur_isobindRateModelcur_rate_in_nis
所以我创建了下一个方法:
$scope.setCurrency=function(currency){
$scope.bindRateModel=parseFloat(currency.cur_rate_in_nis);
};
和设置 ng-change="setCurrency(currency)" 但问题是我得到:
TypeError: Cannot read property 'cur_rate_in_nis' of undefined
另一个奇怪的行为是我在选择开始时得到的空行。
查看我创建小提琴的所有代码....
http://jsfiddle.net/d9esbgjf/5/
谢谢!