gpt4 book ai didi

javascript - 第一次迭代后, Angular ng-grid 选定的项目为空白

转载 作者:行者123 更新时间:2023-11-28 05:44:24 24 4
gpt4 key购买 nike

我正在 ng-grid 上进行批量操作。当选择所有行时,所选项目第一次是正确的,但在第一次批量操作后,所选项目为空白。使用下面的代码,它会发送一条通知“必须选择至少 1 行才能移动”。如果您需要更多详细信息,请告诉我。提前致谢。

vm.init = function() {
vm.title = "Orphan Entries";
selectReport("OrphanEntries");
};
/* initialization */
vm.init();

vm.gridOptionsReports = {
data: 'vm.data',
multiSelect: true,
enableColumnResize: true,
showFooter: true,
showSelectionCheckbox: true,
enableRowSelection: true,
selectWithCheckboxOnly: true,
selectedItems: [],
selectionCheckboxColumnWidth: 25,
enablePaging: true,
pagingOptions: $scope.pagingOptions
}

$scope.applyBulkAction = function(){
if(vm.selectedAction == 'notset'){
Notification.error("You need to select a bulk action.");
}else{
var rows = vm.gridOptionsReports.selectedItems;
if(rows.length < 1){
Notification.error("Must select at least 1 row to move.");
}else{
var toggleTo = 0;
if(vm.selectedAction == 'move'){
toggleTo = 1;
}
var data = "";
var first =true;
for(var i = 0; i< rows.length; i++){
if(rows[i].selectedToBeMoved != toggleTo){
if(first){
data = '{"ID":"'+rows[i].iD+'"}';
first = false;
}else{
data = data + ',{"ID":"'+rows[i].iD+'"}'
}
}
}
if(data == ""){
Notification.error("The rows that you have selected have already been flagged.")
}else{
return ReportService.flagOrphansToBeMoved(data).then(flagOrphansToBeMovedComplete).catch(flagOrphansToBeMovedFailed);

function flagOrphansToBeMovedComplete(response) {
if(!response.data.error && response.data.status == 200){
Notification.success('Bulk action was successful. All flagged rows will be moved during the next scan.');
//vm.gridOptionsReports.selectedItems = [];
vm.init();
}else{
Notification.error('Error scheduling to move orphan.');
}
return response;
}

function flagOrphansToBeMovedFailed(error) {
Notification.error('Error scheduling to move orphan.');
}
}
}
}
}

用户界面

enter image description here

用户界面代码:

<div class="row smallPaddingBot">
<div class="col-sm-2">
<select ng-model="vm.selectedAction" class="form-control">
<option value="notset">Bulk Actions</option>
<option value="move">Flag Selected To Be Moved</option>
<option value="dontMove">Flag Selected Not To Moved</option>
</select>
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-default" ng-click="applyBulkAction()">Apply</button>
</div>

最佳答案

问题是我每次都重新创建 ng-grid,所以我迷失了范围。解决方案是将 gridOptionsReports.selectedItems 设置为范围变量,然后引用该范围变量。

来自:

selectedItems: [],

致:

selectedItems: vm.selectedRow,

还有:

var rows = vm.gridOptionsReports.selectedItems;

致:

var rows = vm.selectedRows;

关于javascript - 第一次迭代后, Angular ng-grid 选定的项目为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38661607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com