Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Pass data from Controller to WebView - event is fire many times...

$
0
0

I pass data from Controller to Webview.

If I click the button "Reload with new message", my webview is reloaded in my contentView, but my event listenner adds permanently.

If I click on my button 5 times, my action is fire 5 times and not 1 times.

Here all my code. Maybe you have an idea of ??what happens?

Thanks.

page.html

<html>
<script>
Ti.App.addEventListener('webPageReady',function(e) {
   Ti.API.info('Info from controller '+e.message);
});
</script>
page.js
var args = arguments[0] || {};
var message = args.message || 'hello';
$.webView.addEventListener('load', function() {
   Ti.App.fireEvent('webPageReady', {message:message});
});
index.js
var currentView = Alloy.createController('page', {message:'message'}).getView();
$.contentView.add(currentView);
 
function pageNewMessage(){
    $.contentView.remove('page');
    currentView = Alloy.createController('page', {message:'new message'}).getView();
    $.contentView.add(currentView);
}
index.xml
<Alloy>
    <Window>
        <View top="0" height="30"><Button onClick="pageNewMessage" title="Reload with new message"/></View>
        <View id="contentView" top="40"/>
    </Window>
</Alloy>

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>