角度js。解析杰森

时间:2016-05-23 08:17:45

标签: javascript angularjs json

我试图解析这个json的大块没有好结果。以下是我的json的样子。我希望能够对所有属性进行ng-repeat,以便我可以渲染例如" Content"和#34;标题"在div里面。

JSON:

{
    "Hits": [{
            "Content": "Lorem ipsum",
            "Id": "Lorem ipsum",
            "IllustratingImage120Url": "Lorem ipsum",
            "SearchPublishDate": "Lorem ipsum",
            "SearchUpdateDate": "Lorem ipsum",
            "Section": "Lorem ipsum",
            "Title": "Lorem ipsum",
            "Url": "Lorem ipsum"
        }, {
            "Content": "Lorem ipsum",
            "Id": "Lorem ipsum",
            "IllustratingImage120Url": "Lorem ipsum",
            "SearchPublishDate": "Lorem ipsum",
            "SearchUpdateDate": "Lorem ipsum",
            "Section": "Lorem ipsum",
            "Title": "Lorem ipsum",
            "Url": "Lorem ipsum"
        }
    }]
}

所以我用服务加载json并将其设置为:

$scope.result = result.data;

Wich返回josn,没问题。但我想对其属性进行ng-repeat。但是整个json都被渲染了。我只想渲染属性"内容"。

HTML:

<ul>
    <li ng-repeat="Content in result">{{ Content }}</li>
</ul>

4 个答案:

答案 0 :(得分:0)

因为它只是json,你可以像这样访问属性:

<ul>
    <li ng-repeat="item in result.Hits">{{ item.Content }}</li>
</ul>

请参阅plnk

答案 1 :(得分:0)

试试这个:

<ul>
    <li ng-repeat="r in result.Hits">{{ r.Content }}</li>
</ul>

答案 2 :(得分:0)

试试这个

<script>
$("document").ready(function(){
    function loadImage(){
        $.ajax({
            type:"POST",
            url:"ajax.php",
            success:function(result){
                $("#banner_div").html(result);
            }
        });
    }
    setInterval(loadImage, 2000);
    loadImage();
});
</script>

&#13;
&#13;
<ul>
  <li ng-repeat="(key,value) in result.Hits">{{ value.Content }}</li>
</ul>
&#13;
var app = angular.module("app",  []);

app.controller('mainCtrl', function($scope){
  $scope.result = {
"Hits": [
{
  "Content": "Lorem ipsum",
  "Id": "Lorem ipsum",
  "IllustratingImage120Url": "Lorem ipsum",
  "SearchPublishDate": "Lorem ipsum",      
  "SearchUpdateDate": "Lorem ipsum",
  "Section": "Lorem ipsum",
  "Title": "Lorem ipsum",
  "Url": "Lorem ipsum"
},
{
  "Content": "Lorem ipsum",
  "Id": "Lorem ipsum",
  "IllustratingImage120Url": "Lorem ipsum",
  "SearchPublishDate": "Lorem ipsum",      
  "SearchUpdateDate": "Lorem ipsum",
  "Section": "Lorem ipsum",
  "Title": "Lorem ipsum",
  "Url": "Lorem ipsum"
}
  ]
};
  });
&#13;
&#13;
&#13;

答案 3 :(得分:0)

我认为问题在于你有一个包含在JSON对象中的数组。

请尝试

docker-compose run api composer install --no-interaction
- Interactive mode is not yet supported on Windows.
Please pass the -d flag when using `docker-compose run`.