我有一个函数,其目的是更新列表,但如果没有几秒的超时,它就无法工作。如果没有设置超时,则仅在我初始化应用程序(重新启动)时更新列表,并且在此超时时,列表会立即更新(根据需要)。 我想知道如何在没有超时的情况下更新它(这导致程序等待额外的时间)。
JS CODE:
$rootScope.$on("uniqueOpenPackage", function (event, package){
importOnlyOnce(package).then(
function (success) {
$rootScope.$broadcast('packageListUpdated', {});
},
function (err) {
console.log("failed promise");
}
)});
function importOnlyOnce(package) {
for (i = 0; i < vm.packageList.data.length; i++) {
//// Package haven't ID in package.json file ////
if (package.package.package.product.id === undefined) {
vm.openPackage(package.package.package);
return;
}
//// if importing exists package ////
else if (package.package.package.product.id === vm.packageList.data[i].product.id) {
var temp = vm.packageList.data[i];
//// if importing opened and exist package ////
if (LoadedPackages.getIndexOfPackageLoaded(temp) != -1){
Package.removePackage(package.package.package);
var packageIndex = LoadedPackages.getIndexOfPackageLoaded(temp) + 1;
LoadedPackages.loadPackage(vm.packageList.data[i]);
return;
}
else{
//// if importing unopened and exist package ////
Package.removePackage(package.package.package);
LoadedPackages.loadPackage(vm.packageList.data[i]);
return;
}
}
}
vm.openPackage(package.package.package);
}
$rootScope.$on('packageListUpdated', function (event, data) {
listPackages();
_setSelectedPackage(undefined);
});