如何清空表格中的项目列表
Posted
技术标签:
【中文标题】如何清空表格中的项目列表【英文标题】:How to empty an item list in a table 【发布时间】:2017-09-08 02:31:02 【问题描述】:我想知道如何清空数组中的元素列表,以仅检索当前元素。 让我解释一下,在我使用的搜索表单中:
一个 addObject 函数,用于在数组中添加一个 id。 还有一个获取此 ID 的 getObject 函数。它第一次运行没有问题并向我显示我想要的数据。在我的数组中,例如:[1]
但是当我返回搜索表单并再次开始操作时,这就是我的数组中的内容:[1,2]
这是我的代码:
我的控制器:
.controller('listCtrl', function($scope, $stateParams, $state, appService)
$scope.search = function ()
appService.searchUser($scope.form).then(function(response)
console.log(response);
$scope.list = response;
);
;
$scope.showInfo = function(currObj)
appService.addObject(currObj);
console.log(currObj);
$state.go('infoJeune');
)
.controller('infoCtrl', function($scope, $stateParams, appService)
$scope.$on('$ionicView.beforeEnter', function (event, viewData)
viewData.enableBack = true;
);
$scope.info = appService.getObject();
console.log($scope.info);
appService.userinfo($scope.info).then(function(response)
$scope.userinfo = response;
console.log($scope.userinfo);
);
)
在我的服务中:
var addObject = function(newObj)
element.push(newObj);
;
var getObject = function()
return element;
;
还有我的模板:
<form ng-controller="listCtrl" id="app-form5" class="list" ng-submit="search()">
<label class="item item-input" id="app-search1" style="">
<i class="icon ion-search placeholder-icon"></i>
<input placeholder="Nom d'un jeune" type="search" ng-model="form.pnom">
</label>
<a class="button button-positive button-block" ng-click="search()">Search</a>
<ion-list id="menu-list1">
<ion-item ng-repeat="user in list track by $index" ng-click="showInfo(user.id)"> user.fname </ion-item>
</ion-list>
</form>
我会尽快回复,谢谢你的回答:)
【问题讨论】:
如果你想让数组在你推送之前为空,那么只需在你的推送语句之前初始化数组 谢谢,我明白了^^ 【参考方案1】:正如 CrazyMac 所说,您必须初始化数组
var addObject = function(newObj)
element = [];
element.push(newObj);
【讨论】:
以上是关于如何清空表格中的项目列表的主要内容,如果未能解决你的问题,请参考以下文章
如何从azure中提取表格中的信息到adroid studio中的列表视图?