2
在我的控制器里面我有两个函数,第一个允许我将新项目添加到数组,第二个删除单个项目。从数组中删除项需要花费很多时间
我的整个控制器看起来是这样的:
.controller('MyCtrl', function($scope, $mdDialog) {
$scope.questions = [{
text: 'What is Your name?',
files: [{
id: 1,
name: 'file 1'
}]
}, {
text: 'Question 2',
files: [{
id: 1,
name: 'file 1'
}]
}, {
text: 'Question 3',
files: [{
id: 1,
name: 'file 1'
}]
}];
$scope.selectedQuestionIndex = undefined;
$scope.selectedQuestion = function(index) {
if ($scope.selectedQuestionIndex !== index) {
$scope.selectedQuestionIndex = index;
} else {
$scope.selectedQuestionIndex = undefined;
}
};
$scope.addFile = function(question) {
question.files.push({
id: 2,
name: 'file 2'
});
};
$scope.deleteFile = function(question, file) {
var index = question.files.indexOf(file);
question.files.splice(index, 1);
};
});
下面是Plunker显示问题:http://plnkr.co/edit/YYxeHlubDk0VThmQNmw4?p=preview
我的问题是:如何加快删除分配给问题的文件(我应该如何优化deleteFile函数)?
@ArunPJohny我使用'ngClick'两个添加和删除。添加速度很快,但删除速度很慢。从'ngClick'延迟会影响两个按钮? – Misiu
@ArunPJohny,我比这更多... – Rayon
对不起......延迟发生在角度方面......在调用'deleteFile'来渲染UI之后 –