【问题标题】:ng-repeat in table row [closed]表行中的 ng-repeat [关闭]
【发布时间】:2015-10-08 09:56:47
【问题描述】:

我无法让它工作。我想用从角度获得的数据构建一个表。我的 php 看起来不错。从我在网上找到的示例中,我的 html 看起来不错。但是我看不出有什么问题。

我的html代码:

<div class="box">
<div class="box-header">
  <h3 class="box-title"><?php echo $lang['LBL_LIST_INSTRUCTORS']; ?></h3>
</div><!-- /.box-header -->
<div class="box-body">
  <table id="instructors" class="table table-bordered table-striped table-hover">
    <thead>
      <tr>
        <th><?php echo $lang['LBL_EDIT']; ?></th>
        <th><?php echo $lang['LBL_NAME']; ?></th>
        <th><?php echo $lang['LBL_ID']; ?></th>

      </tr>
    </thead>
    <tbody>
        <tr ng-repeat="id in instructors">                                      
          <td>
            <button class="btn" ng-click="editUser(id.id)">
              <span class="glyphicon glyphicon-pencil"></span>  Edit
            </button>
          </td>
          <td>{{ id.name }}</td>
          <td>{{ id.id }}</td>
        </tr>
    </tbody>

  </table>
</div><!-- /.box-body -->
</div><!-- /.box -->

JS

var AppInstructor = angular.module('instructorApp', []);

AppInstructor.controller('instructorCtrl', function($scope, $http) {

    getInstructors(); 
    function getInstructors(){
    $http.post("php/getAllInstructors.php").success(function(data){
        $scope.instructors = data;
       });
    };

});

var MyApp = angular.module('biqs_instructor_app', ['instructorApp']);

我的 php 返回的内容:

[{"id":"3","Code":"JJ","Name":"Jan Janssen","Name2":"","Address":"Bergveld 22","Address2":"","City":"9000 Gent","Contact":"","PhoneNo":"03 223 223","OurAccountNo":"","Blocked":"0","Priority":"0","FaxNo":"","VATRegistrationNo":"","GenBusPostingGroup":"","PostCode":"","County":"","EMail":"","HomePage":"","VATBusPostingGroup":"","Notification":"1","ColorPlanning":"green","Birthday":"2015-07-09 14:03:31","RecruitmentDate":"0000-00-00 00:00:00","LocationCode":"","CalendarCode":"","LicenceType":""}

错误:

TypeError: Cannot read property 'insertBefore' of null
    at forEach.after (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:3168:13)
    at Object.JQLite.(anonymous function) [as after] (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:3252:17)
    at Object.$provide.$get.options.enter (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:4671:23)
    at ngRepeatTransclude (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:24509:26)
    at publicLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:6956:29)
    at directiveName.$get.boundTranscludeFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:7096:16)
    at controllersBoundTransclude (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:7756:18)
    at ngRepeatAction (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:24502:15)
    at Object.$watchCollectionAction [as fn] (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:14110:13)
    at Scope.promises.$get.Scope.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js:14243:29)

【问题讨论】:

    标签: javascript php angularjs


    【解决方案1】:

    尝试将&lt;tr&gt;...&lt;/tr&gt; 元素包装在&lt;div&gt;...&lt;/div&gt; 中。

    希望对你有帮助。

    看起来与problem类似的问题

    【讨论】:

    • 我试过这个,但它没有解决问题:
      {{ id.Name }} {{ id.EMail }} {{ id.Notification }} {{ id.Name }} {{ id.ColorPlanning } } {{ id.id }}
    • 这对我有用 jsfiddle.net/dm94719f/2 请确认您在讲师中有数组。
    【解决方案2】:

    这对我有用,所以问题可能出在php上,但不知道。

                  <table id="instructors" class="table">
                <thead>
                  <tr>
                    <th></th>
                    <th>Name</th>
                    <th>ID</th>
                  </tr>
                </thead>
                <tbody ng-repeat="item in instructors">
                    <tr >
                      <td>
                         <span ng-click="editUser(item.id)" class="glyphicon glyphicon-pencil"></span>  Edit
                      </td>
                      <td>{{item.Name}}</td>
                      <td>{{item.id}}</td>
                    </tr>
                </tbody>
    
              </table>
    

    【讨论】:

    • 我试过这个:
      这给了我正确的数据。所以我猜php没问题
    【解决方案3】:

    我发现了问题所在。

    Table id 与 angular 相同。

    【讨论】:

    • 这应该是对原帖的评论。如果您要添加答案,请将编辑后的代码与更多详细信息一起发布,以便其他人可以从错误中吸取教训。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多