[英]AngularJs: How to bind a object with ng-options
我實現了一個下拉菜單,其中我試圖使用ng-options從數據庫中填充下拉菜單,但是當數據到來時,它進入一個沒有鍵或值的對象,如下圖所示。將ng選項用作:-通過使用ng-option
<tr>
<td nowrap>Billing Method:</td>
<td>
<select id="listBillingMethod" data-ng-options="blngmthod as blngmthod for blngmthod in listBillingMethod" ng-model="custom.listBillingMethod" style="width: 182px !important; height: 34px;"></select>
</td>
<td nowrap></td>
<td></td>
</tr>
如果我嘗試使用ng-repeater做同樣的事情,它會給我想要的結果,即我的下拉列表將被填充。我的ng-repeater代碼:
<tr>
<td nowrap>Billing Method:</td>
<td>
<select id="listBillingMethod" style="width: 182px !important; height: 34px;">
<option value="0">--- Select an option ---</option>
<option data-ng-repeat="blngmthod in listBillingMethod">{{blngmthod}}</option>
</select>
</td>
<td nowrap></td>
<td></td>
</tr>
我的數據有以下形式:
看看這個小提琴,如果ur數據對象沒有修改它的鍵,那么您應該真正使用ng-options,因此它適合ng-options示例
<form>
<select ng-model="group"
ng-options="o.value as o.label for o in myGroups"
ng-change="tellUs()"/>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.