Event listeners for dynamic content in evently

让人想犯罪 __ 提交于 2019-12-24 10:39:16

问题


I am generating a dynamic html table. One of the columns in the table has a clickable image (a href). For testing, I have also created a static table, with similar structure as the dynamic table, in the same div.

I have defined a selectors/a/click.js event handler, which works fine for the links in the static table, but not in the dynamic table.

It seems that, since the table is dynamically generated, evently is not attaching any event handlers to it.

Could somebody suggest a workaround for this?


回答1:


I found a workaround: use live instead of bind in the evently library:

cd vendor/couchapp/_attachments
cat jquery.evently.js  | sed -e 's!\.bind(!.live(!'

I'll try to push this upstream into evently.




回答2:


Alternatively, you may lay your events in a following way:

table/<event>/selectors/a/click.js

(where is event responsible for filling your dynamic table, for example _changes). This ensures that the events are being bound after table is generated.



来源:https://stackoverflow.com/questions/7982493/event-listeners-for-dynamic-content-in-evently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!