請幫我解決我的問題我對angularjs有點陌生,我的問題是當只有一個專案時,我需要能夠在選擇選項中設定默認值,因為它是一個動態選擇選項,它有另一個下拉串列有很多專案但沒關系,當必須使用 ng-options 在選擇選項中只選擇一個專案時需要什么
<select class="form-control form" ng-model="relatedTo" style="height: 40px;" ng-options="c.CUSTCODE as c.CUSTNAME ' - ' c.CUSTCODE for c in customers | filter:code" > </select><span style="color:red" ng-show="type === 9 || type !== 9"></span>
角度JS
$http.post('commandCenter.aspx/allCustomer', {}).then(
function onSuccess(response) {
$scope.customers = JSON.parse(response.data.d);
console.log($scope.customers); },
function onError(response) {
console.log('error !!! ');
});
圖1 這張圖沒問題,因為他有很多物品清單。
圖二 當只有一項時,必須是默認或選中。

uj5u.com熱心網友回復:
@MrJami 所說的話。在代碼中類似
$http.post('commandCenter.aspx/allCustomer', {}).then(
function onSuccess(response) {
$scope.customers = JSON.parse(response.data.d);
if ($scope.customers.length === 1) {
$scope.relatedTo = $scope.customers[0].CUSTCODE;
}
console.log($scope.customers); },
function onError(response) {
console.log('error !!! ');
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345321.html
