2016-03-03 43 views
0

我的JSON中包含帳戶,聯繫人和票據信息。它將使用ng-repeat輸出AccountContact作爲下拉菜單,爲用戶提供選項。這是完美的,直到AccountContact只有一個值。帶JSON的Ng選項的問題

HTML

<select class="form-control input-sm" 
    id="accountSelect" ng-model="option.account" 
    ng-options="account.id as account.name for account in accounts | orderBy: 'name'"> 
</select> 

的JavaScript

$scope.accounts = info.Account.Account; 

JSON的實施例(簡化的)

{ 
    "Account":{ 
     "Account":{ 
     "id":1234567, 
     "name":"Account Name", 
     "phone":"123-456-7890" 
     }, 
     "count":1 
    }, 
    "Contacts":{ 
     "Contacts":[ 
     { 
      "id":1234, 
      "name":"Smith, John", 
      "accountID":1234567 
     }, 
     { 
      "id":56789, 
      "name":"Smith, Jane", 
      "accountID":1234567 
     } 
     ], 
     "count":2 
    } 
} 

對我來說,select選項都是由undefined值填充。如果有多個Account,這工作正常。這是爲什麼?

+0

試試這個排序依據:「account.name」」 –

+0

這並沒有不幸解決此問題,所有的選項都仍然'undefined' – CaptainQuint

回答

2

您的Account.Account是一個對象而不是array。您的帳戶應爲array

像:

"Account":{ 
     "Account":[{ 
     "id":1234567, 
     "name":"Account Name", 
     "phone":"123-456-7890" 
     }], 
     "count":1 
    } 
+0

完美到我的PHP文件做了一些調整!創建JSON數據來解決這個問題,它就像一個魅力。非常感謝。 – CaptainQuint