Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在角度控制器中重新渲染ng表格_Javascript_Angularjs_Ngtable - Fatal编程技术网

Javascript 在角度控制器中重新渲染ng表格

Javascript 在角度控制器中重新渲染ng表格,javascript,angularjs,ngtable,Javascript,Angularjs,Ngtable,我在ng表上遇到了一个相当奇怪的问题。下面是我的控制器中一些代码的摘录 this.category = "Open"; this.category = ["Open", "Accepted", "Rejected"]; this.dataItems = []; var _this = this; this.$scope.$watch("vm.category", function(category) { _this.dataItems.length = 0; // To clear

我在ng表上遇到了一个相当奇怪的问题。下面是我的控制器中一些代码的摘录

this.category = "Open";
this.category = ["Open", "Accepted", "Rejected"];
this.dataItems = [];

var _this = this;

this.$scope.$watch("vm.category", function(category) {
    _this.dataItems.length = 0; // To clear items already in the array  

    svc.getApplications(category).then(
        function(okResult) {
            angular.copy(okResult.data, _this.dataItems);

            _this.tableParams = new NgTableParams(
            {
                page: 1,
                count: 5,
                sorting: {
                    applicationDate: 'desc'
                }
            },
            {
                total: _this.dataItems.length,
                getData: function ($defer, params) {
                    var filtered = params.filter() ? _this.$filter('filter')(_this.dataItems, _this.filter) : _this.dataItems;
                    var ordered = params.sorting() ? _this.$filter('orderBy')(filtered, params.orderBy()) : filtered;

                    params.total(ordered.length);
                    if (params.total() < (params.page() - 1) * params.count()) {
                        params.page(1);
                    }

                    $defer.resolve(ordered.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                }
            }
    });
ng表如下所示:

<select id="cbCategory" class="form-control" data-ng-model="vm.category" data-ng-options="category for category in vm.categories"></select>
<table class="table table-striped table-hover" id="tb1" data-ng-table="vm.tableParams">
    <tbody>
        <tr data-ng-repeat="item in $data">
            <td data-title="'Email'" data-filter="{ email: 'text' }" data-sortable="'email'">{{item.applicant.email}}</td>
            <!-- more... -->
        </tr>
    </tbody>
</table>

{{item.applicator.email}
这就是我面临的问题的本质:表格第一次呈现良好/正常。当我更改category下拉列表上的选择时,会调用
getApplications
,甚至会执行行
\u this.tableParams=new NgTableParams
(我已经调试了代码以确认它,并且服务调用执行时没有错误)。但是,
getData
不知何故没有启动,因此UI上没有任何更改。我已经广泛使用了ng表,但这是我第一次以这种方式重新渲染它。我错过了什么?
为免生疑问,在某个地方有
controllerAs:vm

不确定上面的代码为什么不起作用,但控制器中的逻辑稍微重新组织一下就起作用了:

this.category = "Open";
this.category = ["Open", "Accepted", "Rejected"];
this.dataItems = [];

var _this = this;

_this.tableParams = new NgTableParams(
{
    page: 1,
    count: 5,
    sorting: {
        applicationDate: 'desc'
    }
},
{
    total: _this.dataItems.length,
    getData: function ($defer, params) {
        var filtered = params.filter() ? _this.$filter('filter')(_this.dataItems, _this.filter) : _this.dataItems;
        var ordered = params.sorting() ? _this.$filter('orderBy')(filtered, params.orderBy()) : filtered;

        params.total(ordered.length);
        if (params.total() < (params.page() - 1) * params.count()) {
            params.page(1);
        }

        $defer.resolve(ordered.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
}

this.$scope.$watch("vm.category", function(category) {
    _this.dataItems.length = 0; // To clear items already in the array  

    svc.getApplications(category).then(
        function(okResult) {
            angular.copy(okResult.data, _this.dataItems);

            // ADDED THIS...
            if (_this.tableParams) {
                _this.tableParams.reload();
            }
    });
this.category=“打开”;
this.category=[“打开”、“接受”、“拒绝”];
this.dataItems=[];
var_this=这个;
_this.tableParams=新的NgTableParams(
{
页码:1,
计数:5,
分类:{
应用日期:“描述”
}
},
{
总计:_this.dataItems.length,
getData:函数($defer,params){
var filtered=params.filter()?_this.$filter('filter')(_this.dataItems,_this.filter):_this.dataItems;
var ordered=params.sorting()?_this.$filter('orderBy')(filtered,params.orderBy()):filtered;
参数总计(有序长度);
如果(params.total()<(params.page()-1)*params.count()){
参数第(1)页;
}
$defer.resolve(ordered.slice((params.page()-1)*params.count(),params.page()*params.count());
}
}
此.$scope.$watch(“vm.category”,函数(category){
_this.dataItems.length=0;//清除数组中已有的项
getApplications(类别)。然后(
函数(okResult){
复制(okResult.data,_this.dataItems);
//添加了这个。。。
if(_this.tableParams){
_this.tableParams.reload();
}
});

请注意,我尝试将
reload()
放在其他几个地方,但它不起作用

不确定上面的代码为什么不起作用,但控制器中的逻辑稍微重新组织一下,使它起作用:

this.category = "Open";
this.category = ["Open", "Accepted", "Rejected"];
this.dataItems = [];

var _this = this;

_this.tableParams = new NgTableParams(
{
    page: 1,
    count: 5,
    sorting: {
        applicationDate: 'desc'
    }
},
{
    total: _this.dataItems.length,
    getData: function ($defer, params) {
        var filtered = params.filter() ? _this.$filter('filter')(_this.dataItems, _this.filter) : _this.dataItems;
        var ordered = params.sorting() ? _this.$filter('orderBy')(filtered, params.orderBy()) : filtered;

        params.total(ordered.length);
        if (params.total() < (params.page() - 1) * params.count()) {
            params.page(1);
        }

        $defer.resolve(ordered.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
}

this.$scope.$watch("vm.category", function(category) {
    _this.dataItems.length = 0; // To clear items already in the array  

    svc.getApplications(category).then(
        function(okResult) {
            angular.copy(okResult.data, _this.dataItems);

            // ADDED THIS...
            if (_this.tableParams) {
                _this.tableParams.reload();
            }
    });
this.category=“打开”;
this.category=[“打开”、“接受”、“拒绝”];
this.dataItems=[];
var_this=这个;
_this.tableParams=新的NgTableParams(
{
页码:1,
计数:5,
分类:{
应用日期:“描述”
}
},
{
总计:_this.dataItems.length,
getData:函数($defer,params){
var filtered=params.filter()?_this.$filter('filter')(_this.dataItems,_this.filter):_this.dataItems;
var ordered=params.sorting()?_this.$filter('orderBy')(filtered,params.orderBy()):filtered;
参数总计(有序长度);
如果(params.total()<(params.page()-1)*params.count()){
参数第(1)页;
}
$defer.resolve(ordered.slice((params.page()-1)*params.count(),params.page()*params.count());
}
}
此.$scope.$watch(“vm.category”,函数(category){
_this.dataItems.length=0;//清除数组中已有的项
getApplications(类别)。然后(
函数(okResult){
复制(okResult.data,_this.dataItems);
//添加了这个。。。
if(_this.tableParams){
_this.tableParams.reload();
}
});
请注意,我尝试将
reload()
放在其他几个地方,但没有成功