我正在模拟一个模拟他的JSON响应的REST调用,以便为某些输入提供一些数据。
我的模拟JSON是
{
"data": {
"result": [
{
"dispatch_type": "tipo dispatch",
"distribution_code": "DD01",
"jolly_type": "jolly",
"vat_required": true,
"flow_desc": "flow",
"output": "ouput"
}
]
},
"errors": {}
}
我的js是:
DispatcherFilterFactory.paramsMock().then(function(response) {
debugger;
var result = response.data;
$scope.searchFilterDispatcher.dispatchType = result.dispatch_type ;
$scope.searchFilterDispatcher.VAT = result.vat_required ;
$scope.searchFilterDispatcher.dispatchOutput = result.output ;
});
我确定正确解析了JSON,因为当我尝试调试我的var result
时,内部有更正数据,但是当执行命令$scope.searchFilterDispatcher.dispatchType = result.dispatch_type ;
时,他返回的错误是他无法获得未定义的dispatch_type
答案 0 :(得分:-1)
DispatcherFilterFactory.paramsMock().then(function(response) {
var result = response.data.result[0];
$scope.searchFilterDispatcher.dispatchType = result.dispatch_type ;
$scope.searchFilterDispatcher.VAT = result.vat_required ;
$scope.searchFilterDispatcher.dispatchOutput = result.output ;
});