【问题标题】:Angular.js ng-repeat no data using jsonAngular.js ng-repeat 没有使用 json 的数据
【发布时间】:2014-09-03 16:33:34
【问题描述】:

我有一个我正在做的项目,我有一个 json 数组(稍后将来自 Web 服务)

我正在尝试使用 ng-repeat 将该数据加载到表中。 (我以前做过,这次只是把我缺少的东西粘贴到我身上)

我在这里将代码发布到 github:https://github.com/sheets/Sch

我也很乐意在这里发布代码:

<body ng-app="MyApp">
<div ng-controller="SchCtrl">

    <table class="table table-striped table-bordered">
        <thead>
        <th width="15%">Date and Time</th>
        <th width="50%">Provider</th>
        <th width="15%">Location</th>
        <th width="10%">Map</th>
        </thead>
        <tbody>
        <tr ng-repeat="appointment in appointments | orderBy:'startDatetime':true">
            {{appointments.startDatetime | date:'MM/dd/yyyy HH:mm'}}
            {{appointments.providerName}}
{{appointments.apptLocation}}</tr></tbody></table>


</div>
</body>

和 app.js:

var app = angular.module("MyApp", []);

app.controller("SchCtrl", function($scope, $http) {
    $http.get('/appointments.json').
        success(function(data, status, headers, config) {
            $scope.appointments = data;
        }).
        error(function(data, status, headers, config) {
            // log error
        });
});

【问题讨论】:

  • 一方面...你没有&lt;td&gt;
  • 已删除以进行调试。

标签: javascript json angularjs


【解决方案1】:

尝试访问appointment.startDatetime 而不是appointments.startDatetimeproviderNameapptLocation 相同。基本上删除约会中的s

【讨论】:

    【解决方案2】:

    你可以看看this simple exaple
    1. 您需要将所有数据包装在 TD 标签中
    2. 要访问您的数据 - 您需要这样做,例如 data.appointments
    3. 在ng-repeat 中,您需要访问您的 appointments 数组中的每个项目 - 这就是 appointment

    【讨论】:

      【解决方案3】:

      不应该吗

      $scope.appointments = data.appointments
      

      ? 然后你必须访问

      appointment.<field_name>
      

      【讨论】:

        猜你喜欢
        • 2017-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多