我有一个带有属性的数组,我正在尝试在加载时选择某个数组。
我的每个属性都有属性对象、类型对象和属性值数组。
我想用 selected=true 选择属性值
这是我的 Angular 代码:
app.controller('MainCtrl', function($scope) {
$scope.profileData = { "attributes": [{
"attribute": {
"id": 56,
"name": "Hárlitur",
"typeID": 5,
"visibleToUsers": true
},
"type": {
"id": 5,
"typeName": "list"
},
"attributeValues": [{
"id": 109,
"attributeID": 56,
"value": "Ljós",
"chosen": true
}, {
"id": 110,
"attributeID": 56,
"value": "Dökkur",
"chosen": false
}],
"valueText": null
}]};
$scope.changeValue = function changeValue(attribute, value) {
alert(JSON.stringify({"attributeID":attribute.attribute.id, "type": attribute.type.typeName, "value":value.id}));
};
});
这是我的 HTML 代码:
<div ng-repeat="attribute in profileData.attributes">
<select ng-change="changeValue(attribute, attributeValue)" ng-options="item.id as item.value for item in attribute.attributeValues" ng-model="attributeValue.id"></select>
</div>
这是我的插件: http ://plnkr.co/edit/VMbmSB?p=preview