mui.預載入頁面,傳值失敗
阿新 • • 發佈:2018-11-19
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();