简体   繁体   English

Backbone.Marionette视图元素初始化位置

[英]Backbone.Marionette view element initialization location

I have a general question regards where I should do view element addin initialzation. 我有一个一般性的问题,我应该在哪里查看元素加载项的初始化。 Say for instance I have a typeahead plugin that requires initialization like so. 举例来说,我有一个typeahead插件,它需要像这样的初始化。

$(element).typeahead();

Using Backbone.Marionette where is the best place todo this type of view specific code? 使用Backbone.Marionette,在哪里进行这种特定于视图的代码的最佳位置是哪里? My original thought was to override the onRender() method in my view class and do this specifically everytime for elements I know about at design time. 我最初的想法是在我的视图类中重写onRender()方法,并且每次都针对设计时知道的元素专门执行此操作。 However, I would like a more general approach like monitoring the newly added dom elements and checking if element has an identifier like 'data-typeahead' and then automatically initialising it. 但是,我想要一个更通用的方法,例如监视新添加的dom元素并检查元素是否具有诸如“ data-typeahead”之类的标识符,然后自动对其进行初始化。 However, I don't know any jQuery function that would do this? 但是,我不知道会执行此操作的jQuery函数吗? Or even if this is a realistic idea in terms of the overhead of dom parsing especially on mobile devices? 还是就dom解析的开销而言(尤其是在移动设备上)这是一个现实的想法?

Any thoughts / ideas on how to solve this or where to best place to do this sort of code would be awesome! 关于如何解决这个问题或在哪里最好的地方进行这种代码的任何想法/想法都很棒!

Thanks 谢谢

Jon 乔恩

对于那些感兴趣的人,我使用@Trond建议并在onShow方法中实现了视图init语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM