【发布时间】:2016-02-17 10:58:48
【问题描述】:
在我的控制器中,我有两个功能,第一个允许我向数组添加新项目,第二个允许我删除单个项目。
我的整个控制器如下所示:
.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的延迟应该会影响两个按钮? -
@ArunPJohny,我需要的不止这些……
-
对此感到抱歉...延迟发生在角度方面...在调用
deleteFile来呈现 UI 之后 -
这是由ngAnimate和css过渡时间引起的
-
调整css中的过渡时间
标签: javascript angularjs