以combobox angularjs显示数据数组

时间:2016-07-05 09:55:46

标签: javascript angularjs html5

我想从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放入组合框?

亲切的问候

2 个答案:

答案 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}"
          }]
        }};
      });

solution

答案 1 :(得分:0)

这就是诀窍!

ng-options="currencyFormat as currencyFormat.displayValue for currencyFormat in vm.datasource.currencyFormat"