【发布时间】:2016-12-30 04:54:31
【问题描述】:
我们需要在收件箱中实现提前输入功能,但是当我们从 $http 得到响应时,得到的 JSON 是无效的,所以我不能这样做。
以下我用于视图级别的方法
uib-typeahead="name for name in collections ($viewValue)"
角度:
$scope.collections = function(val) {
return $http.get('/Documents/DocumentsList/', {
params : {
stk : val
}
}).then(
function(response) {
if (response.data.suggestions) {
$("[uib-typeahead-popup].dropdown-menu").css('display','block');
return response.data.suggestions
.map(function(item) {
return item.term;
});
};
});
};
JSON 响应:
{} && {
"name": "John",
"age": 31,
"city": "New York"
}
如何将无效的 JSON 修改为有效的 JSON,然后传递有效的响应。
【问题讨论】:
-
为什么不修复实际的端点响应,使其成为有效的 JSON?
-
在您的 JSON 响应中没有看到
suggestions。您希望它如何工作? -
@Phil:是的,你是对的。提供的 json 不是实际响应 JSON,它是唯一的示例格式
标签: angularjs json angularjs-scope typehead