方法一:url 傳參
1、不安全,可以直接從url里面看到傳輸?shù)男畔ⅲ?/p>
2、只適用于數(shù)據(jù)量小的情況頁(yè)面之間傳遞參數(shù),超過(guò)限額跳轉(zhuǎn)頁(yè)面會(huì)報(bào)404錯(cuò)誤;
3、回退上一頁(yè)面時(shí)數(shù)據(jù)會(huì)丟失,若要保留之前的表單數(shù)據(jù)代碼繁瑣,易出錯(cuò)。
//url帶參數(shù)的頁(yè)面跳轉(zhuǎn)
$scope.jumpDetail = function ($index,x) {
sessionStorage.setItem('transDateFrom',$scope.searchCondition.transDateFrom);
sessionStorage.setItem('transDateTo',$scope.searchCondition.transDateTo);
window.location.href="/dist/local/cloud.html#/orm/detail?id="+ x.saleReportNo ;

}
// 初始化頁(yè)面
$scope.initPageData = function () {
$scope.searchCondition.transDateFrom=sessionStorage.getItem('transDateFrom');
$scope.searchCondition.transDateTo=sessionStorage.getItem('transDateTo');
if($scope.searchCondition.transDateFrom!==null &&
$scope.searchCondition.transDateTo!==null){
$scope.getTable();

sessionStorage.removeItem('transDateFrom');
sessionStorage.removeItem('transDateTo');
}
$scope.initPage = true;
$scope.getDiIndSelectOption();
};
注:這里的是為了保證頁(yè)面回退是仍保留上一頁(yè)的原始數(shù)據(jù);
//接受上個(gè)頁(yè)面?zhèn)鬟f的參數(shù)
$scope.GetRequest = function () {
var url = window.location.hash; //獲取url中"#"符后的字串

var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
$scope.searchCondition.saleReportNo = theRequest[strs[i].split("=")[0]];
}
}

return theRequest;
}
方法二:傳參
1、一次存入數(shù)據(jù),后面所有子頁(yè)面都能隨時(shí)調(diào)用,關(guān)閉瀏覽器則數(shù)據(jù)清除,安全高效;
2、存儲(chǔ)容量大,大約在5M左右;
3、每個(gè)子頁(yè)面都能增加/刪除數(shù)據(jù);
4、在客戶端實(shí)現(xiàn)數(shù)據(jù)臨時(shí)存儲(chǔ),極大減輕了服務(wù)器壓力。
//用sessionStorage方法保存參數(shù),然后實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
var _sessionName = 'saleReportNo';
sessionStorage.setItem(_sessionName, x.saleReportNo);

window.open('http://localhost:8081/dist/local/cloud.html#/orm/detail');
// 獲取參數(shù)saleReportNo,并傳入查詢條件中
var saleReportNo = sessionStorage.getItem("saleReportNo");
if (saleReportNo) {
$scope.searchCondition.saleReportNo = saleReportNo;
$scope.getTable();
sessionStorage.setItem("saleReportNo", "");
}
方法三:傳參
與用法k類似,唯一的區(qū)別是前者是儲(chǔ)存本地時(shí)間為永久有效,除非手動(dòng)清除,因此適用于一些特殊的業(yè)務(wù)場(chǎng)景。
注:客戶端存儲(chǔ)數(shù)據(jù)的方法是html5新加入的頁(yè)面之間傳遞參數(shù),目前絕大多數(shù)主流瀏覽器都支持這項(xiàng)html5技術(shù),IE瀏覽器也從8開(kāi)始支持。