1723538179@qq.com
1723538179@qq.com
  • 发布:2017-04-05 11:59
  • 更新:2017-04-05 12:55
  • 阅读:1147

evalJS无法执行webview外链的js文件内的js代码吗?

分类:HTML5+

如题。

let wvCurr, member, wait, wvHome;  
let $list = DOM.get("#list");  
let $pager = DOM.get("#pager");  
let isNoMore = false;  
let pageSize = 20;  
let pageIndex = 1;  
let userList = {};  
let isPullupdate = false;  
let isFirstLoad = true;  

mui.plusReady(function(){  
    wvCurr = plus.webview.currentWebview();  
    wvCurr.setStyle({background:'#fff'})  
    member = FD.getCurrentMember();  
    **wvHome = plus.webview.getWebviewById("home.html");**  
    console.log(wvHome)  
    wait = FD.showWaiting();  

    getList();  

    FD.setPullToRefresh(wvCurr, function(callback){  
        pageIndex = 1;  
        isNoMore = false;  
        isPullupdate = true;  
        getList(callback);  
    },{style:"circle"});  
});  

//上拉加载  
FD.setPullDownToLoad(function(){  
    if(isNoMore){ return; }  
    $pager.innerHTML = "正在加载...";  
    getList();  
});   

mui(document).on("tap", ".consults-2 li", function(){  
    let target = "online-ask.html";  
    let receiveUserId = parseInt(this.getAttribute("data-uid"));  

    mui.openWindow({url: target, id: target, extras: {receiveUser: userList[receiveUserId]}});  
});  

//获取咨询列表  
function getList(callback){  

    let url = FD.appDomain ;  
    let data = {CurrentDoctorUserId: member.uid, TakeNum: pageSize, Page: pageIndex};  

    console.log(JSON.stringify(data));  

    mui.ajax(url, {  
        type: "GET",  
        data: data,  
        success: function(result){  
            if(isFirstLoad){  
                console.log(wvHome)  
                **wvHome.evalJS('getNewReminds();');**  
                isFirstLoad = false;  
            }  

            wait.close();  
            console.log(JSON.stringify(result));  

            if(typeof callback === "function"){  
                callback();  
            }  

            if(!result.Bool){  
                FD.showAlert({msg: result.ErrorMessage});  
                return;  
            }  

            let list = result.Data.List;  

            if((!list || list.length < 1) && pageIndex === 1){  
                $list.innerHTML = '<p class="tips-text">没有咨询信息</p>';  
                return;  
            }  

            if(result.Data.Count > pageSize){   
                $pager.classList.remove("hidden");   
            }else{  
                $pager.classList.add("hidden");  
            }  

            if(result.Data.Count > pageIndex * pageSize){  
                $pager.innerHTML = "正在加载...";  
            }else{  
                $pager.innerHTML = "没有更多了";  
                isNoMore = true;  
            }  

            if(isPullupdate){  
                wvHome.evalJS('getNewReminds();');  
                isPullupdate = false;  
                $list.innerHTML = '';  
                wait.close();  
            }  

            let buffer = '';  

            list.forEach(function(item){  
                buffer += '<li data-uid="'+ item.UserId +'"><dl><dt>';  
                buffer += '<img id="'+ item.UserId +'" src="'+ item.ImgUrl +'"/></dt><dd>';  
                buffer += '<h5 class="big-black">'+ item.UserName +'</h5>';  
                buffer += '<p class="big-gray">'+ item.Tittle +'</p>';  
                buffer += '<time class="small-gray">'+ moment(item.CreateTime).format("YYYY-MM-DD HH:mm") +'</time>';  
                //buffer += '<span>[重要]</span>';  
                buffer += item.NewCount > 0 ? '<span class="new-num-tip">'+ item.NewCount +'</span>' : '';  
                buffer += '</dd></dl></li>';  

                userList[item.UserId] = item;  
                setTimeout(function(){ FD.setPhotoMargin(item.ImgUrl, "" + item.UserId, 50); }, 50);  
            });  

            DOM.append($list, buffer);  
            pageIndex++;  
        },  
        error: function(xhr, type, msg){  
            console.log(msg);  

            if(!msg){  
                FD.requestAgain(getList);  
            }  
        }  
    });  
}

wvHome.evalJS执行getNewReminds()报错,把getNewReminds()函数写在script标签内而不是引入js文件才能执行

2017-04-05 11:59 负责人:无 分享
已邀请:
amourz

amourz

evalJS要拼接字符串,很麻烦,用mui.fire自定义事件吧

要回复问题请先登录注册