2016-12-05 110 views
0

這裏選擇的是情景默認值從服務器

我得到的數據從服務器以這種形式

$scope.data=[ 
{"name":"xyz","status":"pending"}, 
{"name":"abc","status":"completed"}, 
{"name":"pqr","status":"completed"} 
] 

這個數據是Seprate GET需要不同的狀態

$scope.statusValues=[ 
{"statusName":"pending","id":"1"}, 
{"statusName":"completed","id":"2"}, 
{"statusName":"cancelled","id":"3"}, 
{"statusName":"custom","id":"4"} 
] 

HTML中: -

<div ng-repeat="t in data">{{t.name}}</div> 

如何顯示有更多$ scope.statusValues

enter image description here

+1

使用'NG-selected'比賽,像這樣'NG-model' ........................ ........'' – cna327

回答

1

您可以使用ng-options顯示所有的狀態和ng-model選擇方法內t.status值綁定到你的數據狀態

var app = angular.module('myApp', []); 
 
app.controller('myCtrl', function($scope) { 
 
    $scope.data = [{ 
 
    "name": "ABC", 
 
    "statusId": "1", 
 
    "status": "completed" 
 
    }, { 
 
    "name": "XYZ", 
 
    "statusId": "2", 
 
    "status": "pending" 
 
    }, { 
 
    "name": "PQR", 
 
    "statusId": "3", 
 
    "status": "assigned" 
 
    }]; 
 

 
    $scope.statusValues = [{ 
 
    "statusId": "1", 
 
    "status": "completed" 
 
    }, { 
 
    "statusId": "2", 
 
    "status": "pending" 
 
    }, { 
 
    "statusId": "3", 
 
    "status": "assigned" 
 
    }, { 
 
    "statusId": "4", 
 
    "status": "cancelled" 
 
    }, { 
 
    "statusId": "5", 
 
    "status": "customstatus" 
 
    }, { 
 
    "statusId": "6", 
 
    "status": "customstatus2" 
 
    }]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    <div ng-repeat="t in data"> 
 
    {{t.name}} 
 
    <select ng-model="t.status" ng-options="s.status as s.status for s in statusValues"></select> 
 
    </div> 
 
</div>

編輯

如評論中所述更新陣列

+0

謝謝來回答覆!!但仍然默認情況下,狀態值沒有被選擇..因爲它來自服務器.. –

+0

什麼是默認值? – Weedoze

+0

from Data array ... {{t.status}} .. –

1

使用鍵值對進行組合。

I have created plunker it may helpful. 

Plunker

+0

謝謝你回覆!但仍然默認狀態值沒有被選擇..因爲它來自服務器.. –

+0

我已經創建靜態替換它與服務器響應。 –

+0

Exactly.Static數據工作正常..只要我這樣做與服務器GET調用..它不選擇默認值{{t.status}} –