在jqMobi Nav中绑定主干事件,或者当dom中的dom元素重复时

时间:2012-05-31 04:26:22

标签: backbone.js jqmobi

我一直在移植我的应用程序以使用jqMobi和jqUI,但我遇到了骨干委托事件的问题。

jqUI创建侧导航栏的方式是嗯....至少可以说有趣。

每个面板都可以有一个独特的导航栏,但导航栏实际上永远不会对用户可见,您填充导航栏,然后jqUI将html复制到div#menu元素中。

我的观点相当简单

MyApp.Views.UserMenu = Backbone.View.extend({
  el: 'nav#user_menu',

  initialize: function(){
    //empty out and unbind in-case it is already populated
    $(this.el).empty().unbind();

    this.render();
  },

  events: {
    "click div#add_friend": "new_friend"
  },

  render: function(){
    $(this.el).append(HandlebarsTemplates['friends/new_friend']());

    // here I am trying to change the 'el' to point to where the menu is in the DOM
    this.el = 'div#menu';                        
    this.delegateEvents();
    return this;       
  },

  new_friend: function(){
    alert('clicked');
  }
});

我在填充el后尝试将div#menu更改为nav,但这不起作用。我也试过直接填充div#menu,但这似乎也不起作用。

有什么建议吗?我假设问题是元素被移动,但它可能是其他东西,也许我不知道如何调试其他情况。

0 个答案:

没有答案
相关问题