我想从json对象中显示组合框中的数据。
<select ng-model="vm.datasource.currencyFormatChoice" ng-options="currencyFormatChoice as currencyFormatChoice for currencyFormatChoice in vm.datasource.currencyFormat"></select>
这是我拥有的json对象。现在我想将displayValue设置为组合框。
"currencyFormat": [ { "displayValue": "€ 1.000,00", "value": "{0:C2}" }, { "displayValue": "€ 1.000", "value": "{0:C0}" }, { "displayValue": "$ 1,000.00", "value": "{0:C2}" }, { "displayValue": "$ 1,000", "value": "{0:C0}" }, { "displayValue": "1.000,00", "value": "{0:N2}" }, { "displayValue": "1.000", "value": "{0:N0}" }, { "displayValue": "1,000.00", "value": "{0:N2}" }, { "displayValue": "1,000", "value": "{0:N0}" } ]
使用HTML代码我得到[object Object]而不是1000美元。如何将displayValue放入组合框?
亲切的问候
答案 0 :(得分:0)
我修好了你,看看下面的小提琴。
<div ng-app="myapp">
<fieldset ng-controller="FirstCtrl">
<select ng-model="modelValue" ng-options="currencyFormatChoice.displayValue for currencyFormatChoice in vm.datasource.currencyFormatChoice"></select>
</fieldset>
</div>
var myapp = angular.module('myapp', []);
myapp.controller('FirstCtrl', function($scope) {
$scope.modelValue = {};
$scope.vm = {
datasource: {
currencyFormatChoice: [{
displayValue: "€ 1.000,00",
value: "{0:C2}"
}, {
displayValue: "€ 1.000",
value: "{0:C0}"
}, {
displayValue: "$ 1,000.00",
value: "{0:C2}"
}, {
displayValue: "$ 1,000",
value: "{0:C0}"
}]
}};
});
答案 1 :(得分:0)
这就是诀窍!
ng-options="currencyFormat as currencyFormat.displayValue for currencyFormat in vm.datasource.currencyFormat"