Backbone.js的活动具有约束力。像"委托" jQuery中? [英] Backbone.js Events binding. Like "delegate" in Jquery?

查看:94
本文介绍了Backbone.js的活动具有约束力。像"委托" jQuery中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Backbone.js的新。我看到,在Backbone.js的,事件绑定:

I'm new in backbone.js. And I see that in Backbone.js, the events binding :

var PersonView = Backbone.View.extend({
    ....
    events : {
        "click button.btnSay" : "saySomething"
    },

    saySomething : function(){
        ....
    }
    ...
});

...不需要button.btnSay在调用的时候存在,这是如此的相似,委托jQuery中。

...doesn't need the button.btnSay to be existed in the time of calling, that's so similar to "delegate" in Jquery.

而现在的问题是,我们可以在HTML页面中更改任何按钮 .btnSay (由萤火虫,等等)。他们eventualy得到听众。怎能prevent呢?

And now, the problem is, we can change any button in our html page to .btnSay (by Firebug, etc.). And they eventualy get the listeners. How can we prevent this?

推荐答案

有没有类似委托它使用委托(除非该事件不具有选择器)。本次活动在骨干结合看起来是这样的:

It isn't similar to delegate it does use delegate (unless the event doesn't have a selector). The event binding in Backbone looks like this:

if (selector === '') {
  $(this.el).bind(eventName, method);
} else {
  $(this.el).delegate(selector, eventName, method);
}

所以它使用委托视图的元素。至少限制事件到视图中的元素

So it uses delegate on the view's element. That at least limits the events to elements within the view.

您不能瞎搞与你的内容和事件调试器停止的人。他们可以改变HTML,CSS的,甚至编辑您的JavaScript,所以你不能从你的网页上造成的麻烦阻止他们。您可以从弄得一团糟的服务器上,虽然阻止他们,只是不相信任何骨干网发送到您的服务器和验证一切你所验证其他任何从外部世界来以同样的方式。

You can't stop people from messing around with your elements and events in a debugger. They can change the HTML, the CSS, and even edit your JavaScript so you can't stop them from causing trouble on your page. You can stop them from making a mess on your server though, just don't trust anything that Backbone sends to your server and validate everything the same way you would validate anything else that comes in from the outside world.

基本上,不要浪费你的时间去担心别人用你的HTML /事件/ JavaScript的插科打诨砸自己的脸用砖头。让他们伤害了自己所有他们想要的。但是不要通过不与外界相信任何保护您的服务器(和你的服务器甚至不应该相信自己比他们有更多的)。

Basically, don't waste your time worrying about someone smashing their own face with a brick by messing with your HTML/events/JavaScript. Let them hurt themselves all they want. But do protect your server by not trusting anything from the outside world (and your servers shouldn't even trust themselves any more than they have to).

这篇关于Backbone.js的活动具有约束力。像"委托" jQuery中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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