Angularjs ng-repeat指令问题

时间:2016-01-25 22:21:03

标签: angularjs jinja2

的index.html

{% extends "base.html" %}
{% block header %}

{% endblock %}

{% block body %}
    <div ng-controller="SCTestList">
        [[messages]]
        <tr ng-repeat="item in messages">
          <td>[[item.id]]</td>
          <td>[[item.carrier]]</td>
          <td>[[item.phoneNumber]]</td>
          <td>[[item.shortcode]]</td>
          <td>[[item.sentTime]]</td>
          <td>[[item.MOs]]</td>

        </tr>
    </div>
<script src="{{url_for('static', filename='js/test.js')}}"></script>


{% endblock %}

test.js

var myApp = angular.module('myApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

function SCTestList($scope, $http) {
    $http.get('http://localhost:5000/api/MT').
        success(function(data) {
            $scope.messages = data.json_list;
        });
}

SCTestList.$inject = ['$scope'];
angular.module('myApp').controller('SCTestList', ['$scope', '$http', SCTestList]);

json从http请求返回

{
  "json_list": [
    {
      "MOs": [
        {
          "id": 3,
          "incomingTime": "2016-02-17 03:22:55",
          "msgID": 123123132123,
        },
        {
          "id": 2,
          "incomingTime": "2016-01-17 03:22:55",
          "msgID": 123123132123,
        }
      ],
      "id": 1,
      "msgID": 123123132123,
      "sentTime": "2016-01-17 03:22:55",
    },
    {
      "MOs": [],
      "id": 2,
      "msgID": 123123132143,
      "sentTime": "2016-01-17 03:22:55",
    }
  ],
  "totalPages": 1
}

页面上的输出

[{"MOs":[{"id":3,"incomingTime":"2016-02-17 03:22:55","msgID":123123132123},{"id":2,"incomingTime":"2016-01-17 03:22:55","msgID":123123132123}],"id":1,"msgID":123123132123,"sentTime":"2016-01-17 03:22:55"},{"MOs":[],"id":2,"msgID":123123132143,"sentTime":"2016-01-17 03:22:55"}] 

显然,消息对象在范围内,因为它是在文档上输出的,但由于某种原因,我无法让应用程序循环遍历数组元素。这里有什么我想念的吗?

如果我在ng-repeat指令中打印$ index,我看不到任何打印出的内容,所以它根本就没有循环。

1 个答案:

答案 0 :(得分:1)

您的标记不正确,tr内有div。将tr包裹在table中以获得有效标记。

相关问题