'点击'原型中的观察者
我有一个页面,其中包含多个 div(每个 div 都有一个唯一的 ID 和相同的类“父级”)。在每个“父”div 下方,是一个具有类“child”和唯一 ID 名称 -child 的 div。该 DIV 在页面加载时为空。
每当您单击父 DIV 时,都会执行以下代码。
$$('div.parent').each(function(s){
$(s).observe('click', function(event){
event.stop();
var filer = $(s).readAttribute('filer');
var currentElement = $(s).id;
var childElement = currentElement + '-children';
new Ajax.Updater ({success: childElement}, root + '/filers/interfacechildren', {
parameters: {parentId: currentElement, filer: filer}
});
});
});
当然,子节点有可能再次成为其自身的父节点。响应看起来像这样(带有 Zend Framework 的 Smarty):
{foreach from=$ifaces item=interface}
<div id="{$interface->name}" filer="{$interface->system_id}" class="parent">{$interface->name}</div>
<div id="{$interface->name}-children" class="child"></div>
{/foreach}
每当我单击在子项中加载的“父”div 时,没有任何反应:( 有任何建议/修复如何解决此问题吗?
I have a page which contains several divs (each with a unique ID and the same class, 'parent'). Underneath each "parent" div, is a div with class "child" and unique ID name -child. This DIV is upon page load empty.
Whenever you click on a parent DIV, the following code is executed.
$('div.parent').each(function(s){
$(s).observe('click', function(event){
event.stop();
var filer = $(s).readAttribute('filer');
var currentElement = $(s).id;
var childElement = currentElement + '-children';
new Ajax.Updater ({success: childElement}, root + '/filers/interfacechildren', {
parameters: {parentId: currentElement, filer: filer}
});
});
});
Of course, it's possible that a child node is again a parent ont its own. The response looks like this (Smarty with Zend Framework):
{foreach from=$ifaces item=interface}
<div id="{$interface->name}" filer="{$interface->system_id}" class="parent">{$interface->name}</div>
<div id="{$interface->name}-children" class="child"></div>
{/foreach}
Whenever I click on a "parent" div that is loaded inside a child, nothing happens :( Any suggestions / fixes how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 event.stop() 移到 Ajax.Updater 之后?
Move event.stop() after the Ajax.Updater?
已修复。
我将代码放入一个函数中,并使其在成功时自行递归。这样,当新的父级加载 AJAX 时,观察者函数就会考虑新创建的 div。
Fixed.
I put the code inside a function, and made it recurse itself onSuccess. That way, when the new parents are loaded with AJAX, the observer function takes into account the new created divs.