【问题标题】:When I use Events in Parse the listener callback is not executed, after calling the trigger with the event当我在 Parse 中使用事件时,在使用事件调用触发器后,不执行侦听器回调
【发布时间】:2015-09-08 10:41:40
【问题描述】:

我正在使用 Parse SDK for BackboneJS,当我尝试使用事件时,通过监听这样的事件

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()

并在这个函数中触发事件:

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'

对象扩展 Parse 事件:

object = {};
_.extend(object, Parse.Events);

但是,即使在事件触发之后,回调也不会执行。

我在文档中关注了他们的example。有什么东西可以阻止事件被触发或收听吗?我用错了吗?

这是我的 full module。它运行顺利,没有错误。但是,on 函数的回调没有被执行。

【问题讨论】:

  • “不起作用”没有关于它如何不起作用的信息。除非您使用 如何 进行扩展,否则它不起作用(错误、警告或无操作) - 谁能提供帮助?
  • “不起作用”是指on函数附带的回调代码没有被执行。没有引发警告或错误。

标签: javascript events backbone.js parse-platform


【解决方案1】:

我认为这种情况是domReady 回调在loadNavigationBar() 之后被触发,所以实际上你在监听之前触发了事件,你可以检查何时调用app.initContents 并确保在domReady 之后调用它使用@以987654325@为例查看

【讨论】:

  • 是的,没错。 app.initContent()domReady 之前被调用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-27
  • 1970-01-01
  • 2020-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多