I am using Parse SDK for BackboneJS and when I try to use Events, by listening to an event like this
object.on 'OnRender', ->
if sessionData["is-pilot"] is "true"
$("#notifications-list").remove()
$("#messages-list").remove()
$("#buidler-list").remove()
$("#invoice-menu").remove()
$("#logs-menu").remove()
$(".piloty").remove()
$(".navbar-toggle").on "click", ->
if $("html").hasClass("nav-open")
$("html").removeClass "nav-open"
$("body").removeClass "nav-open"
else
$("html").addClass "nav-open"
$("body").addClass "nav-open"
LoadBrandObjects.loadBrandProductTypes()
LoadBrandObjects.loadBrandStores()
LoadBrandObjects.loadBrandProducts()
And triggering the event in this function:
loadNavigationBar = ->
$(".header").load "templates/app-nav-part.html", ->
logoURL = sessionData["brand-logo-url"] or 'images/ta3rifah1.png'
brandName = sessionData["brand-name"] or 'Ta3rifah Client'
if brandName.length > 30
brandName = "#{brandName.slice(0,27)}..."
$("#profile-menu").html "
<img class=\"js-brand-logo\" width=\"34\" height=\"34\" src=\"#{logoURL} \" />
<div class=\"js-header-brand-name inline-block \">#{brandName}</div>
<b class=\"caret\"></b>
"
customizeNavBarForPackages()
customizeNavBarForUser()
# where I trigger the event ----------*******---------------
object.trigger 'OnRender'
and the object extends Parse events:
object = {};
_.extend(object, Parse.Events);
But, the callback is not executed, even after the event is triggered.
I've followed their example in the docs. Is there anything that could block the event from being triggered or listened to? am I using it in a wrong way?
Here is my full module. It runs smoothly without errors. But, the callback of on
function isn't executed.
I think the case is domReady
callback is getting fired after loadNavigationBar()
so in reality you are triggering the event before listening can you can check when app.initContents
is being called and ensure it's called after domReady
use console.log()
for example to check