草庐IT

LayoutInflater_Delegate

全部标签

ruby-on-rails - 带有委托(delegate)和条件的事件记录

是否可以在您的ActiveRecord模型中使用委托(delegate)并在其上使用类似:if的条件?classUser:master,:if=>:has_master?belongs_to:master,:class_name=>"User"defhas_master?master.present?endend 最佳答案 不,你不能,但你可以传递:allow_nil=>true选项以在master为nil时返回nil。classUser:master,:allow_nil=>true#...enduser.master=nilus

javascript - 事件委托(delegate),Event.target 与 Event.currentTarget

在MDNEvent.targetreference有一个关于实现事件委托(delegate)的例子:事件委托(delegate)示例//Assumingthereisa'list'variablecontaininganinstanceofan//HTMLulelement.functionhide(e){//Unlesslistitemsareseparatedbyamargin,e.targetshouldbe//differentthane.currentTargete.target.style.visibility='hidden';}list.addEventListener

javascript - 为什么悬停在委托(delegate)事件处理程序中不起作用?

我正在动态添加一些元素并在委托(delegate)事件处理程序中为其分配一个悬停属性,我在下面的代码中使用了它,但它不起作用。$(document).on("hover",".sec_close_fast",function(){$(this).parent('div').parent('div').css("border","3pxsolid#000000");});然后我使用mouseover并且它起作用了:$(document).on("mouseover",".sec_close_fast",function(){$(this).parent('div').parent('di

javascript - 哪些 JavaScript 库有事件委托(delegate)?

我想试用一个新的JavaScript库。使用(和喜爱)jQuery1.3's"Live"events,我更喜欢我尝试将事件委托(delegate)内置到事件系统中的下一个库。Wikipedia'sJSLibraryComparison在这里工作失败。看起来像MooToolsisgettingitin2.0.其他人呢?我正在制作这个社区Wiki。请帮我填写一下。Prototype:nojQuery:asof1.3MooTools:asof2.0ExtJS:yes 最佳答案 事件委托(delegate)比您想象的要容易。如果我找到一个没

javascript - 使用 Hammer.js 的事件委托(delegate)

我如何在Hammer.js中使用纯JavaScript执行jQuery样式的事件委托(delegate)?例如:Hammer(document).on('tap','.item',function(){console.log('tapped')})这是直接可行的还是我必须自己进行授权? 最佳答案 受Jools回答的启发,这就是我的想法。我没有考虑纯JS解决方案——事实上,这是为与Backbone.View一起使用而设计的,但很容易适应其他情况。当它到达View的根元素(this.el)时,它将停止攀登节点树。从HammerJS事件标

javascript - 删除特定对象上的 jQuery 委托(delegate)事件处理程序

我已使用单个选择器将委托(delegate)事件处理程序附加到页面上的多个元素。由于事件是为单个元素触发的,所以我想仅根据某些条件逻辑关闭该元素的事件处理程序。这意味着我不一定要在第一次点击时禁用该事件。但如果不关闭所有这些,我不知道该怎么做。HTML:OneTwoThreeJS:$(document).on('click','button',function(ev){//doesn'tworkbecauseargumentneedstobeastring$(document).off('click',$(ev.target));//doesn'tdowhatIwantb/cturns

javascript - 在 JavaScript 和 jQuery 中使用委托(delegate)事件处理程序是否存在性能缺陷?

我在我的JavaScript代码中使用委托(delegate)事件处理程序(jQuery),因此当单击动态添加的按钮时会发生一些事情。我想知道这是否存在性能缺陷?//Delegatedeventhandler$(document).on('click','#dynamicallyAddedButton',function(){console.log("Hello");});在性能方面,它与此相比如何?//Regulareventhandler$("#regularButton").on('click',function(){console.log("HelloAgain");});查看

javascript - MS Edge 无法检测 <use> SVG 元素的委托(delegate)事件?

我想我在MSEdge中发现了一个令人不安的错误,它会影响动态创建的SVG元素。Edge似乎能够检测到直接绑定(bind)的事件,即$('.use').on('click',...),但是委托(delegate)事件$('body').on('click','use',...)被忽略。它最容易用JSFiddle来说明(在Chrome中测试,绑定(bind)都有效,而在Edge中委托(delegate)绑定(bind)不起作用):https://jsfiddle.net/Lr0arahb/有没有人对此问题有任何见解,并且知道可能的解决方法?最重要的是,我正在寻找一个我们仍然可以使用的解决方

javascript - 无法让 jstree 工作 - "Uncaught TypeError: Object #<Object> has no method ' 委托(delegate)'”

我正在尝试让jstree插件工作,遵循此页面上的“预定义HTML”示例:http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/1_datasources.html为了避免与可能发生的任何其他事情发生冲突,我试图让它在尽可能简单的页面中工作,在我的公共(public)保管箱文件夹中:http://dl.dropbox.com/u/846812/jstree_example/jstree_example.html我在我的页面中包含的唯一js是jquery和主jstree文件,jsTree/j

javascript - jquery delegate() 事件(mouseover mouseout)触发两次

我有以下脚本总是两次触发鼠标悬停和鼠标移出!你建议我做错了什么(解除绑定(bind),返回例如)?我尝试了一些东西但是没有任何帮助。代码如下:$('#container').delegate('div.showmenu','mouseovermouseentermouseoutmouseleave',function(e){if(e.type==='mouseover'||e.type==='mouseenter'){//jIErequiresmouseenter,doesnotfiremouseoverif($(this).parents().closest('div').hasCl