javascript - AngularJS 数据表

标签 javascript angularjs

我是 AngularJS 的新手。我遇到一个问题,我的数据没有显示在数据表中。谁能帮我解决这个问题吗?

我的代码

HTML 代码

<div class="content table-responsive table-full-width">
<table id="myTable" class="table table-striped table-hover" datatable="">
    <thead>
        <th>Account ID</th>
        <th>Name</th>
        <th>Email</th>
        <th>Registered On</th>
        <!--<th>Settings</th>-->
        <th>Status</th>
    </thead>
    <tbody>
        <tr ng-repeat="user in users">
            <td style="text-align:left;">{{user.account}}</td>
            <td style="text-align:left;">{{user.name}}</td>
            <td style="text-align:left;">{{user.email}}</td>

            <td style="text-align:left;" ng-model="dateVal">{{user.register}}</td>

            <td style="text-align:left;">

                <span class="label {{ user.status == 1 && 'label-success' || 'label-danger'}} " ng-click="updated(user.id)">
                                             {{ user.status == 1 && 'Active' || 'Inactive'}}
                                            </span>

            </td>

            <td>
                <a href="index.html#/edit_userpermission?id={{user.id}}" class="fa fa-cog" data-toggle="modal" data-target="#myModal"></a>
            </td>
        </tr>
    </tbody>
</table>

JS代码

 /* User Listing */
  var url = UserService.url+'users.php?token='+localStorage.getItem("token");

  $http.get(url).success( function(data) 
  {

     $('#myTable').DataTable();

     if(data.login != null ){
       $location.path( "/logout" );      
     }
     $scope.users = data;

  });

我得到的输出为... Output

当我单击排序选项时,它显示“表中没有可用数据”... 为什么会发生这种情况? 等待回复。提前致谢

最佳答案

保重。

0- 您必须将数据表定义为 ng。所以,在你的行中:

<table id="myTable" class="table table-striped table-hover" datatable="">

您必须将其更改为:

<table id="myTable" class="table table-striped table-hover" datatable="ng">

1- 注意每行中的数据数量。因为if的个数不同。它会给你带来一些问题。

2- 您使用 Angular 数据表吗?您必须与 jquery 数据表一起使用。两者都可以使用。

您可以查看这个Plunkr:http://plnkr.co/edit/0lDhg9Mehn72E3rWAsLN?p=preview

另外,您可以在此处查看文档:https://l-lin.github.io/angular-datatables/#/angularWay

关于javascript - AngularJS 数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37724203/

相关文章:

javascript - 为什么不能在 ngFor 中使用 var 而不是 let

angularjs - D3 与 Angular 的集成 : "Error: Invalid value for <rect> attribute x"

javascript - 建立这样的网站所需的技术

css - 强制按钮在 Bootstrap 中水平

javascript - 从 Javascript 对象循环动态创建的表单。如何将数据保存回对象

javascript - 在 HTML 中访问 nextElementSibling

javascript - RXJS - 具有多个键的 dinstinctUntilChange

javascript - 使用 Angular 验证选择字段和单选按钮

javascript - 如何使用chartjs创建折线图?

javascript - 具有混合日期格式的 jquery tablesorter 插件无法在 IE/Safari 中工作,但可以在 FF、O、C 中工作