mui.预加载页面,传值失败

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_39581226/article/details/81477321

1.此为搜索页到列表页的逻辑编写

搜索页面:

mui.init({
	preloadPages: [{
				url: 'order-1-search.html',
				id: 'order-1-search.html'
			}]
	});
	mui.ready(function() {
	initLocalStorage();

	function initLocalStorage() {
		var _localStorage = localStorage,
		Items = _localStorage.Items;
		if(Items !== undefined) {
		var onlyItem = Items.split('|');
		if(onlyItem.length > 0) {
			key = '';
			for(var i = 0; i < onlyItem.length; i++) {
			key = key + '<li>' + onlyItem[i] + '</li>';
			}
		$('.historyList').html(key);
		}
	}
}

function setItems(keyword) {
	var maxNum = 5;
	keyword = keyword.trim();
	var _localStorage2 = localStorage,
		Items = _localStorage2.Items;

	if(Items === undefined) {
		localStorage.Items = keyword;

	} else {
		var onlyItem = Items.split('|').filter(function(e) {
		return e != keyword;
	});
	if(onlyItem.length >= 5) {
						onlyItem = onlyItem.splice(0, maxNum - 1);
	}
	if(onlyItem.length > 0) Items = keyword + '|' + onlyItem.join('|');
	localStorage.Items = Items;
}
}
	$("#delhistory").on('click', function() {
	localStorage.removeItem('Items');
	$('.historyList li').remove();
})
	//标签搜索
$('.historyList li').on('click', function() {
	var Keys = $(this).text().trim();
	setItems(Keys);
	goto(Keys);
	});

var strLoginID = window.localStorage["account"];
var search = document.getElementById("searchstr"); //	监听input框键盘事件	search.addEventListener("keypress", function(e) {
	var Keys = search.value;
	//当e.keyCode的值为13 即,点击前往/搜索 按键时执行以下操作
	if(e.keyCode == 13) {
		if(Keys != '') {
			setItems(Keys);
		}
		document.activeElement.blur(); //软键盘收起
		goto(Keys);
	}
});
$("#go").on(
	"click",
	function() {
	var Keys = $("#searchstr").val();
	if(Keys != '') {
		setItems(Keys);
		}
		goto(Keys);
	});

function goto(Keys) {
	mui.openWindow({
		url: "order-1-search.html", //跳转地址
		id: "order-1-search.html", //id
		show: {
			aniShow: "slide-in-right", //页面显示动画,默认为”slide-in-right“;
			duration: 300, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒
			autoShow: true //页面loaded事件发生后自动显示,默认为true
		},
		extras: { //extras里面的就是参数了
			strKeys: Keys
		},
		waiting: {
			title: '正在玩命搜索...' //等待对话框上显示的提示内容
		}
	})
}
})

列表页面:

	mui.plusReady(function() {
			var strLoginID = window.localStorage["account"];
			var page = plus.webview.currentWebview();
			var strKeys = page.strKeys; //获得参数
			getlist(strLoginID, strKeys);
		});

2.遇到的问题

列表页无法获得搜索页的参数,进行页面渲染

3.解决办法

将搜索页的mui.init();里面的预加载参数删除,就ok了

mui.init();

猜你喜欢

转载自blog.csdn.net/weixin_39581226/article/details/81477321
今日推荐