2015-08-21 48 views
0
<select id="CFG_USERS_DFTLEVEL" name="CFG_USERS_DFTLEVEL" ng-options="obj.CFG_ORGLEVEL_ID as obj.CFG_ORGLEVEL_CODE for obj in items" ng-model="formData.CFG_USERS_DFTLEVEL"> 
<option value="">Select Default Org Level</option></select> 

HTML Code above 

靜態值工作dood..But動態的Json值不工作爲什麼動態選擇框json值不工作?

數據響應輸出:

{"orglevel":[{"CFG_ORGLEVEL_ID":"1","CFG_ORGLEVEL_CODE":"AEB"},{"CFG_ORGLEVEL_ID":"2","CFG_ORGLEVEL_CODE" 
:"MTL"},{"CFG_ORGLEVEL_ID":"3","CFG_ORGLEVEL_CODE":"TOR"}]} 

控制器代碼在這裏:

$http.post('test/test.php',userdata).success(function(data) { 


    var jsondata = JSON.stringify(data['orglevel']); 

/* static value work fine*/ 

//$scope.items = [{ "CFG_ORGLEVEL_ID": 1, "CFG_ORGLEVEL_CODE": "AEB" }, { "CFG_ORGLEVEL_ID": 2, "CFG_ORGLEVEL_CODE": "MTL" }, { "CFG_ORGLEVEL_ID": 2, "CFG_ORGLEVEL_CODE": "TOR" }]; 

$scope.items = jsondata ; //not working 

}); 
+0

嘗試使用'JSON.parse()來'如果你想把它當作一個數組 – AndersRehn

+0

太謝謝你了...它工作正常...謝謝 – shunmugarajan

回答

0

你爲什麼stringify-反應?

data應該已經是一個javascript對象。

只是做$scope.items = data.orglevel;