【发布时间】:2017-10-23 10:26:38
【问题描述】:
我已经在这里阅读了许多问题,但是我并没有点击并理解我遇到的这个问题。
js代码:
app.controller('example_ctrl',['$scope','$http', function($scope,
$http){
$http.get('api_call_here').then(function successCallBack(response){
$scope.response = response;
});
api的json格式:
{
"categoryOne": {
"1": {
"title": "someData1",
"description": "This is number One"
},
"2": {
"title": "moreData1",
"description": "I am not a number, I'm a free man!"
}
}
}
现在因为这没有在数组中返回,所以每当我尝试过滤它时都会出错。举个例子:
<div ng-repeat="(category, object) in response.data">
<div ng-repeat="item in object">
<p>{{item.title}}</p>
</div>
</div>
现在,如果我尝试将 ng-model 放在搜索输入上,并使用 |filter:ng-model 名称将其绑定到 ng-repeat,我会收到错误消息。
我基本上想要做的是,当您在搜索字段中输入文本时,让它只返回包含该文本的标题/描述。
【问题讨论】:
-
您是否检查过您的 api 的输出标头是否设置为 application/json?如果它只是一个字符串,它不会返回真正的 json
-
console.log 结果返回一个对象。
-
您必须将项目映射到数组,因为过滤器不适用于对象
标签: javascript angularjs json