【问题标题】:Angular Smart Table not refreshing on updateAngular 智能表在更新时不刷新
【发布时间】:2016-01-31 14:55:23
【问题描述】:

给定这个控制器和html,刷新回发被调用,但即使有数据,表也不会更新。不知道为什么。

angular.module('umbraco').requires.push('smart-table');
app.controller('adminSection.manageUsersController', [
    '$scope', '$http', 'dialogService', function ($scope, $http, dialogService) {
        var ctrl = this;
        ctrl.members = [];
        ctrl.safeMembers = [];
        ctrl.fetchResults = function fetchResults(tableState) {
            $http.post('/umbraco/backoffice/api/members/search', tableState.search.predicateObject || {codeId: null}).then(function (response) {
                ctrl.members = response.data;
                ctrl.safeMembers = [].concat(ctrl.members);
                console.log(ctrl.safeMembers);
            }, function (response) {
                console.log(response);
                alert("There was an error in the CODE back office app.");
            });
        };

    }
]);

<div class="umb-pane" ng-controller="adminSection.manageUsersController as mc">
  <table st-pipe="mc.fetchResults" st-table="mc.members" st-safe-src="mc.safeMembers" class="table table-striped">
    <thead>
    <tr>
      <th st-sort="codeId">Id</th>
      <th>Name / Job Title / Email</th>
      <th>Access Granted</th>
    </tr>
    <tr>
      <th>
        <input st-search="codeId" placeholder="search code id"/>
      </th>
      <th><input st-search="name" placeholder="search name"/> ( <input st-search="email" placeholder="search email"/> ) of <input st-search="employer" placeholder="search employer"/></th>
      <th></th>
      <th></th>
    </tr>
    </thead>
    <tbody >
    <tr ng-repeat="member in mc.safeMembers">
      <td>{{member.codeId}}</td>
      <td>{{member.fullname}} / {{member.employer}} / {{member.email}}</td>
      <td>{{member.codeId}}</td>
    </tr>
    </tbody>
  </table>
</div>

我遵循了这个例子:link to docs

【问题讨论】:

    标签: angularjs smart-table


    【解决方案1】:

    您的转发器应该在显示的集合上(即成员)

    <tr ng-repeat="member in mc.members">
    

    当你获取你的数据时不需要更新显示的集合

            ctrl.fetchResults = function fetchResults(tableState) {
            $http.post('/umbraco/backoffice/api/members/search', tableState.search.predicateObject || {codeId: null}).then(function (response) {
                ctrl.safeMembers = response.data;
            }, function (response) {
                console.log(response);
                alert("There was an error in the CODE back office app.");
            });
        };
    

    【讨论】:

    • 你给 st-table 的只是一个暴露给模板的变量名,它会在表状态改变时重新创建,你甚至不需要在控制器中声明它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多