簡體   English   中英

ng選項選擇angular js

[英]ng options select angular js

當我嘗試使用具有我離開的格式的安排加載選項時,第一個選項為空白,以下是我的安排的值。 當我嘗試選擇其他選項時,這對我來說是個問題,我無法獲取該值。

<select ng-model='form.type' 
    ng-options="item.name for item in organizations" 
    ng-change="update({{form.type.id}})">
</select>

格式:

{"status":0,"Area":[{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}],"Count":3}

控制器:

$scope.organizations = data.Area;

您的情況是,您的ng-model變量form.type不在選擇下拉列表中包含選項的值。 這就是為什么您看到一個空行。 例如,如果您希望它成為第一個,則可以執行此操作(我將其更改為selected變量,但這一點都沒有關系):

$scope.organizations = [{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}];

$scope.selected = $scope.organizations[0].id;

現在, selected變量具有您的選項的id 但這還不是全部。 您還需要稍微修改HTML,以使ng-optionsid為您的值。 它可以是對象中您想要的任何內容,不一定是id ,但這就是我假設您需要的原因,您可以更改它:

<select ng-model='selected' ng-options="item.id as item.name for item in organizations" ng-change="update({{selected}})">

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM