javascript - add a listener to Cordova events in a Backbone view and not to all document -
javascript - add a listener to Cordova events in a Backbone view and not to all document -
i'd add together listener, cordova
events, in specific view of backbone
, @ moment did using document
:
var view = utils.view.extend({ initialize: function() { document.addeventlistener( "online", function( ) { // cordova event alert("connected"); // .... }, false); } });
but every time alter view , go view
new event listener appended , document has many listeners, need one. how can add together event listener 1 time view , avoid creating new ones every time go view?
thanks
i have solved similar issue in past doing following:
add listener on load of application instead of when view loads
have listener phone call function checks specific variable set true or false
when specific view initialized, set variable true
when specific view replaced, or when other view initialized, set variable false
the function listener calls this:
function onlineeventcallback () { if(app.checkonline) { alert('connected'); } }
this allow listener set once, , create sure returns if specific view initialized.
javascript jquery cordova backbone.js
Comments
Post a Comment