2015-10-06 69 views
0

我有一個json格式的返回數據,我如何使用ng-model將數據加載回下拉爲默認值?角度填充數據下降

<div class="col-md-3 col-md-offset-2"> 
      <h5 class="over-title">Category</h5> 
      <ui-select ng-model="product.categories.selected" theme="bootstrap"> 
       <ui-select-match placeholder="Select Category" ng-model="product.name"> 
        {{$select.selected.name}} 
       </ui-select-match> 
       <ui-select-choices repeat="item in categories | filter: $select.search"> 
        <div ng-bind-html="item.name | highlight: $select.search"></div> 
       </ui-select-choices> 
      </ui-select> 
     </div> 

的JSON如下:

Object { category: "Sightseeing & Tours" } 

當前ng-model=product.name是用來填充選項,當有人創造新的產品。現在,當他們編輯表格時,下拉列表應該列出先前保存的數據,這些數據是由json以上返回的。

時創建新產品下拉列表中選擇功能:

$scope.categories = function(){ 
     Account.getCategoryList() 
     .then(function(response){ 

      $scope.categories = response.data; 
     }) 


     .catch(function(response){ 
      console.log(response.data.messages); 
     }); 

    }; 

的一個返回json當有人編輯回形式

$scope.produk = {}; 
    $scope.getProductToEdit = function(id){ 
     Account.getProductToEdit(id) 
     .then(function(response){ 

      $scope.produk = response.data.product; 
      console.log($scope.produk); ---> Object { category: "Sightseeing & Tours" } 
      return $scope.produk; 
     }) 
     .catch(function(response){ 

     }) 
    } 

新形式的模式:

enter image description here

編輯表格m頌:

enter image description here

我如何可以替換從json在編輯模式下什麼返回的默認下拉菜單。由於

回答