为什么动态选择框json值不起作用?

时间:2015-08-21 10:40:18

标签: angularjs drop-down-menu

<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 ..但动态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

});

1 个答案:

答案 0 :(得分:0)

为什么要对响应进行字符串化?

data应该已经是一个javascript对象了。

只需$scope.items = data.orglevel;