角度智能表在更新时不刷新

时间:2022-05-18 00:02:22

Given this controller and html, the refresh postback is called, but even with data, the table is not updated. Cannot work out why.

给定此控制器和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>

I have followed this example: link to docs

我已经按照这个例子:链接到docs

1 个解决方案

#1


1  

your repeater should be on the displayed collection (ie members)

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

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

And there is no need to update the displayed collection when you fetch your data

并且在获取数据时无需更新显示的集合

        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.");
        });
    };

#1


1  

your repeater should be on the displayed collection (ie members)

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

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

And there is no need to update the displayed collection when you fetch your data

并且在获取数据时无需更新显示的集合

        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.");
        });
    };