<p>选项,{{selected}}</p>
<select ng-model="selected" ng-options="item.id as item.name for item in selectData">
<option value="">-- 请选择 --</option>
</select>
$scope.selected = 1004;
$scope.selectData = [
{id:1001,name:"零零一"},
{id:1002,name:"零零二"},
{id:1003,name:"零零三"},
{id:1004,name:"零零四"}
];
How to get the data of the selected column. selected can only get the id value, but I want the value of this column. And it does not interfere with the default selection of an item through the id value. For example, if I select this item through id:1004, I not only want the id value but also all the items in this column.
Don’t you think there is a contradiction in your needs? You assign an id value to ng-model, but you also expect the value of ng-model to be an object?
If you want the final ng-model to be a column, but you can only give the id value of a selected item (which should be what you encountered during page editing), you can first filter out the corresponding item by giving the id and assign it to selected. And the ng-options expression needs to be changed to
item as item.name for item in selectData track by item.id