I have a trouble all the time.
The question is I use other javascript and html file draw some picture in the webview.
But I change other view and turn back this view , it will crash.
I guess is the draw map listener not remove.
my original is below:
gChart function is in a javascript file, it will deal with some data and return a website.
drawBaseMap function is in the Html5/chart.html .
app.js
var myWebView = Ti.UI.createWebView( { url: 'Html5/chart.html' // -> set url top: 0, left: 0, width: 320 , height: 160 , scalesPageToFit: true } ); myWebView.addEventListener('load',function(e){ myWebView.evalJS("Ti.App.addEventListener('drawBaseMapHandler',function(e){" +"var gObj=gChart(e.strUrl);"+"drawBaseMap(gObj);"+"})"); });api.js
// this fire event is in callback function Ti.App.fireEvent('drawBaseMapHandler',{strUrl:arrData[2]});This method can right run, but when I change view , it will crash.
I guess the "drawBaseMapHandler" listener is not remove.
So I change my code is below.
app.js
var runjs = function(e){ "var gObj=gChart("+Gval.strUrl+");"+"drawBaseMap(gObj);"}; myWebView.addEventListener('load',function(e){ myWebView.evalJS("Ti.App.addEventListener('drawBaseMapHandler', runjs); Ti.App.removeEventListener('drawBaseMapHandler',runjs) "); });Using this metohd can't show on the webview.
Because my Gval.strUrl ( it is global variable) hasn't write data.
I test my code to assign Gval.strUrl value , avoid the time problem.
But the webview still have not show my map.
So I try again to chang my code. below:
I take webview listener to my callback function and remove drawBaseMapHandler listener sentence.
app.js
var myWebView = Ti.UI.createWebView( { url: 'Html5/chart.html' // -> set url top: 0, left: 0, width: 320 , height: 160 , scalesPageToFit: true } ); var callbackFun = function(e) { // e.url have right site pressWebView.addEventListener('load',function(e){ pressWebView.evalJS("var gObj=gChart(" + e.url+");" +"drawBaseMap(gObj);"); }); } require('api').getMyData(Gval, callbackFun );Using this method is not draw my map in mywebview.
why I use other javascript file and html to draw map in chart.html should through custom listener event draw my map only ?
Have any one can give me some suggestion?
I'm appricated your priceless opinions.
Your Answer
This question has been locked and cannot accept new answers.