我正在使用角js中的選擇框。我需要將數據綁定到json中的選擇框,我如何用角度中的選擇框內的數組填充json。我有以下代碼。綁定角js中的json數組選擇選項
HTML
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedName" ng-options="x.names.name for x in names">
</select>
</div>
JS
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = {
"jobs": [
{
"Software": [
{
"name": "Developer",
"displayName": "App Developer"
},
{
"name": "Designer",
"displayName": "App Designer"
}
]
},
{
"Business": [
{
"name": "Sales",
"displayName": "Sales Manager"
},
{
"name": "Marketing",
"displayName": "Head of Marketing"
}
]
}
]
};
});
我如何填充選擇框裏面的JSON $ scope.names。由於json擁有數組,因此我感到很困難。在此先感謝
檢查文檔https://docs.angularjs.org/api/ng/directive/select –
使用'NG-repeat',而不是'NG-option' –
你有什麼期望在最後的狀態看? –