Menulis halaman paparan folder, kemudian untuk melihat subfoldernya, anda masih mesti melompat ke halaman paparan folder, tetapi laluan hanya akan mencetuskan lompatan apabila url berubah Saya mencubanya dalam folder Parameter nombor rawak telah ditambahkan ke URL yang sepadan dengan laluan halaman paparan, tetapi kaedah ini tidak berfungsi sama sekali. Kemudian, ia telah dijadikan teks klik. Selepas folder, saya hanya menukar nilai tatasusunan senarai folder tanpa melompat Walau bagaimanapun, ini tidak mencetuskan penyegaran halaman automatik, jadi saya hanya boleh menggunakan $window.location.reload(true) untuk menyegarkan secara manual, tetapi kesannya sangat. ops, kadang-kadang berkesan, kadang-kadang tidak, tolong bantu saya.
Berikut ialah penghalaan, pengawal dan penghalaan halaman
.state('tab.folder-list', {
url: '/folder-list',
views: {
'tab-more': {
templateUrl: "templates/work/folder/folder-list.html",
controller: "folderCtrl"
}
}
})
Berpadanan controller
halaman
appCtrls.controller('folderCtrl', function ($scope, $state, $window, goBackService, $ionicActionSheet, folderService, $stateParams, localStorageService) {
var isr = false;
$scope.getAllFolderList = function () {
var pro = folderService.isRootFolder(localStorageService.getLocalStorage("current").currentFolderId);
pro.then(function (res) {
$scope.isRoot = res.data;
isr = $scope.isRoot;
})
var promise = folderService.getAllFolderList(localStorageService.getLocalStorage("current").currentFolderId);
promise.then(function (response) {
console.debug("List----->>>" + angular.toJson(response.data));
$scope.folderList = response.data.folderList;
$scope.fileList = response.data.fileList;
localStorageService.setLocalStorage("currentFolderList",$scope.folderList);
}, function (response) {
$scope.folderList = [];
$scope.fileList = [];
}
)
//$window.location.reload(true);
}
//currentFolderId:当前目录Id,previousFolderId:当前目录的上级目录id,用于返回到上级目录
//当点击文件夹列表中的文件夹时,会将点击的该文件夹id(跳转后变成当前目录id),以及跳转前的当前目录id(跳转后就变成了上一级目录id)传过去
//根目录与其他目录不同之处,在于根目录不允许删除,编辑
$scope.goToViewFolder = function (folder) {
var current = {
currentFolderId: folder.id,
previousFolderId: localStorageService.getLocalStorage("current").currentFolderId
};
localStorageService.setLocalStorage("current", current);
$scope.isRoot = false;
var promise = folderService.getAllFolderList(localStorageService.getLocalStorage("current").currentFolderId);
promise.then(function (response) {
$scope.folderList = response.data.folderList;
$scope.fileList = response.data.fileList;
localStorageService.setLocalStorage("currentFolderList",$scope.folderList);
}, function (response) {
$scope.folderList = [];
$scope.fileList = [];
}
)
$window.location.reload(true);
/*var now=new Date();
var number = now.getSeconds();
$state.go("tab.folder-list",{random:number},{reload: true});*/
}
$scope.showAdd = function (folder) {
var menuItems = [
{text: "新建文件"},
{text: "新建文件夹"}
];
// Show the action sheet
var hideSheet = $ionicActionSheet.show({
titleText: "",
buttons: menuItems,
buttonClicked: function (index) {
if (index == 1) {
$state.go("tab.folder-add");
} else {
$state.go("tab.file-chooseWayToGainFile");
}
},
cancelText: "取消",
cancel: function () {
// add cancel code..
}
/*,
destructiveText: "删除",
destructiveButtonClicked:function(){
}*/
});
};
//返回上级目录,刷新列表页
$scope.backToPrevious = function () {
var previousFolderId = "";
//console.debug("previousFolderId-->>"+localStorageService.getLocalStorage("current").previousFolderId);
var promise = folderService.getParentFolderId(localStorageService.getLocalStorage("current").previousFolderId);
promise.then(function (res) {
previousFolderId = res.data;
var current = {
currentFolderId: localStorageService.getLocalStorage("current").previousFolderId,
previousFolderId: previousFolderId
};
localStorageService.setLocalStorage("current", current);
})
var pro = folderService.isRootFolder(localStorageService.getLocalStorage("current").currentFolderId);
pro.then(function (res) {
$scope.isRoot = res.data;
isr = $scope.isRoot;
})
var promise = folderService.getAllFolderList(localStorageService.getLocalStorage("current").currentFolderId);
promise.then(function (response) {
$scope.folderList = response.data.folderList;
$scope.fileList = response.data.fileList;
localStorageService.setLocalStorage("currentFolderList",$scope.folderList);
}, function (response) {
$scope.folderList = [];
$scope.fileList = [];
}
)
$window.location.reload(true);
/*var now=new Date();
var number = now.getSeconds();
$state.go("tab.folder-list",{random:number},{reload: true});*/
}
$scope.goToViewFile = function (file) {
$state.go("tab.file-fileView", {fileId: file.id});
}
$scope.editFolder = function () {
$state.go("tab.folder-edit");
}
});
<ion-view view-title="列表">
<ion-nav-buttons side="right">
<a class="button button-clear" ng-click="editFolder()" ng-show=""><i class="icon ion-ios-compose-outline"></i></a>
<a class="button button-clear" ng-click="showAdd()"><i class="icon ion-android-menu"></i></a>
</ion-nav-buttons>
<ion-nav-buttons side="left">
<a ng-show="isRoot" class="button button-clear" ui-sref="tab.file-companysIBelongTo"><i class="icon ion-ios-arrow-left"></i>公司列表</a>
<a ng-show="!isRoot" class="button button-clear" ng-click="backToPrevious()"><i class="icon ion-ios-arrow-left"></i>返回上级目录</a>
</ion-nav-buttons>
<ion-content class="no-padding" ng-init="getAllFolderList()">
<p class="item item-pider">文件夹列表</p>
<p class="list">
<p class="item item-icon-left item-icon-right" ng-repeat="folder in folderList" ng-click="goToViewFolder(folder)">
<i class="icon ion-android-folder"></i>
{{folder.name}}
<i class="icon ion-chevron-right icon-accessory"></i>
</p>
</p>
<p class="item item-pider">文件列表</p>
<p class="list">
<p class="item item-icon-left item-icon-right" ng-repeat="file in fileList" ng-click="goToViewFile(file)">
<i class="icon ion-android-document"></i>
{{file.name}}
<i class="icon ion-chevron-right icon-accessory"></i>
</p>
</p>
</ion-content>
</ion-view>
http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref
用ui-sref-opts参数