搜索

首页  >  问答  >  正文

html - angularJS 循环拿json数组

我在jsp页面定义了一个变量:
<script type="text/javascript">


var wpmagazine=[{"title":"11","content":"coco"},
                {"title":"22","content":"nana"}];

</script>
然后在下面想要用angularJS 循环json数组,该怎么做?

           <p class="zxzz-cont" ng-repeat="">
                <p class="zx-img"><a href="#"><img src="img/new_img1.jpg" /></a></p>
                <p class="zx-text">
                    <p class="zx-tit"><a href="#">title</a></p>
                    <p class="zx-zy">content</p>
                </p>
            </p>
淡淡烟草味淡淡烟草味2750 天前586

全部回复(1)我来回复

  • 为情所困

    为情所困2017-05-15 17:01:22

    <body ng-app="myApp">
    <script type="text/javascript">
        var wpmagazine = [
            {"title": "11", "content": "coco"},
            {"title": "22", "content": "nana"}
        ];
    </script>
    
    <p ng-controller="MyCtrl">
        <p class="zxzz-cont" ng-repeat="item in wpmagazine">
    
            <p class="zx-img">
                <a href="#">
                </a>
            </p>
            <p class="zx-text">
                <p class="zx-tit"><a href="#">{{item.title}}</a></p>
                <p class="zx-zy">{{item.content}}</p>
            </p>
        </p>
    </p>
    <script src="angular.js"></script>
    <script>
        var app = angular.module('myApp', []);
    
        app.controller('MyCtrl', function ($scope) {
            $scope.wpmagazine = wpmagazine;
        });
    </script>
    </body>
    

    既然使用了angualr,不要采用这种方式去获取数据

    回复
    0
  • 取消回复