search

Home  >  Q&A  >  body text

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>
淡淡烟草味淡淡烟草味2745 days ago581

reply all(1)I'll reply

  • 为情所困

    为情所困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>
    

    Since you are using angualr, do not use this method to obtain data

    reply
    0
  • Cancelreply