javascript - angular ng-table 官方的例子我做了一早上一晚上就是做不出来....
迷茫
迷茫 2017-04-11 11:47:23
[JavaScript讨论组]

1.ng-table的例子已经做的让我怀疑人生了....难道我是隐藏的智障?

不废话 直接上code:

先是controller里面注入NgTableParams
然后html:

<p ng-controller="editStoreItemController" class="pageback">
    <table ng-table="editStoreItemController.tableParams" class="table table-condensed table-bordered table-striped">
          <tr ng-repeat="row in $data">
            <td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
            <td data-title="'Age'" filter="{age: 'number'}" sortable="'age'">{{row.age}}</td>
            <td data-title="'Money'" filter="{money: 'number'}" sortable="'money'">{{row.money}}</td>
            </tr>
    </table>
</p>

然后js:

app.controller("editStoreItemController", editStoreItemController);
  editStoreItemController.$inject = ["NgTableParams"];

  function editStoreItemController(NgTableParams) {
    var simpleList=[{ name: 'christian', age: 21 }, { name: 'anthony', age: 88 }];
    var self = this;
    self.tableParams = new NgTableParams({}, {
      dataset: simpleList
    });
  }

结果:在浏览器中,只显示

这个东西,其他数据都没有,都要挠破头了;

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(3)
天蓬老师

找到原因了~~ 看看区别在哪里,对于新手来说坑的很

<p ng-controller="editStoreItemController as vm" class="pageback">
    <table ng-table="vm.tableParams" class="table table-condensed table-bordered table-striped">
        <tr ng-repeat="row in $data">
        <td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
      <td data-title="'Age'" filter="{age: 'number'}" sortable="'age'">{{row.age}}</td>
      <td data-title="'Money'" filter="{money: 'number'}" sortable="'money'">{{row.money}}</td>
      </tr>
  </table>
</p>

  app.controller("editStoreItemController", editStoreItemController);
  editStoreItemController.$inject = ["NgTableParams"];

  function editStoreItemController(NgTableParams) {
    var simpleList=[{ name: 'christian', age: 21 }, { name: 'anthony', age: 88 }];
    var vm= this;
    vm.tableParams = new NgTableParams({}, {
      dataset: simpleList
    });
  }
黄舟

显然页面没有问题 但你定义的值没有获取到

你在这个控制器定义了 var self = this

建议你用 ng-table="self.tableParams"


<p ng-controller="editStoreItemController" class="pageback">
    <table ng-table="vm.tableParams" class="table table-condensed table-bordered table-striped">
        <tr ng-repeat="row in $data">
        <td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
      <td data-title="'Age'" filter="{age: 'number'}" sortable="'age'">{{row.age}}</td>
      <td data-title="'Money'" filter="{money: 'number'}" sortable="'money'">{{row.money}}</td>
      </tr>
  </table>
</p>

  app.controller("editStoreItemController", editStoreItemController);
  editStoreItemController.$inject = ["NgTableParams"];

  function editStoreItemController(NgTableParams) {
    var simpleList=[{ name: 'christian', age: 21 }, { name: 'anthony', age: 88 }];
    var vm= this;
    vm.tableParams = new NgTableParams({}, {
      dataset: simpleList
    });
  }
  

怪我咯
<p>
<table ng-table="self.tableParams" class="table table-condensed table-bordered table-striped">
    <tr ng-repeat="row in $data">
      <td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
      <td data-title="'Age'" filter="{age: 'number'}" sortable="'age'">{{row.age}}</td>
      <td data-title="'Money'" filter="{money: 'number'}" sortable="'money'">{{row.money}}</td>
    </tr>
</table>
</p>

app.controller("demoController", demoController);
  demoController.$inject = ["NgTableParams"];
  function demoController(NgTableParams) {
        console.log("running 1");
    var self = this;
        var simpleList=[{ name: 'christian', age: 21 }, { name: 'anthony', age: 88 }];
    self.tableParams = new NgTableParams({}, {
      dataset: simpleList
    });
  }

控制台 只有log的 running 1

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号