Backbone.js和jquery将click事件绑定到视图函数 [英] Backbone.js and jquery binding click event to a view function

查看:50
本文介绍了Backbone.js和jquery将click事件绑定到视图函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用lobb.js,这是我的情况

I am using backbone.js here is my scenario

假设我有一个名为 FooView

class FooView extends Backbone.view

  initialize:->
    $('#manage-foo').bind('click', @render)

  render: ->
    //whatever I want to render

我想绑定元素#manage-foo上的单击以呈现我的视图或调用我的视图的函数FooView,但我不想丢失调用该函数的上下文,应调用函数render.使用 this 指向FooView而不是元素如何实现此目的.?

I want to bind the click on the element #manage-foo to render my view or to call a function of my view FooView but I do not want to loose context in which the function is called, the function render should be called with this pointing to the FooView rather than the element How do I achieve this. ?

我遇到的情况是,我在pageLoad上创建了FooView,并且在单击Give元素时必须显示它.

The case that I have is that I create the FooView on pageLoad and I have to show it when a give element is clicked

谢谢

推荐答案

不确定是否能100%回答您的问题,但 _.bindAll(this,'render'); 可以解决上下文丢失的问题.您可以添加所需的所有方法,因此可以 _ .. bindAll(this,'render,click'); 并添加click方法.

Not sure if this answers your question 100% but _.bindAll(this, 'render'); fixes the loss of context. You can add all of the methods for which you need to do this with, so you can _.bindAll(this, 'render,click'); and add a click method.

http://arturadib.com/hello-backbonejs/docs/1.html

这篇关于Backbone.js和jquery将click事件绑定到视图函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆