重用复杂HTML片段的最佳方法(Best way to reuse a complex HTML fragment)

编程入门 行业动态 更新时间:2024-10-14 16:25:45
重用复杂HTML片段的最佳方法(Best way to reuse a complex HTML fragment)

我想重用我使用下划线模板创建的复杂UI的html。 问题是模板构造函数获取数据并生成带有数据的纯HTML。 现在,我想缓存生成的html以供将来用作模板,并通过使用jQuery选择器选择每个html节点来更改特定html节点的数据。

我的目标是通过在创建后重复使用JS和DOM对象来减少内存消耗。

以前有人做过这样的事吗?

I want to reuse the html of a complex UI that I created using underscore template. The issue is that the template constructor takes the data and generates the plain html with data. Now, I want to cache the generated html for future to use it as a template and would change the data of specific html nodes by selecting each of them using jQuery selectors.

My goal is to reduce the memory consumption by keep re-using the JS and DOM objects once created.

Has anybody done something like this before?

最满意答案

好的。 我自己找到了办法。 我正在缓存由下划线模板准备的DOM片段(无需从主体中删除)。 当下次需要相同的片段时,我通过使用jQuery选择器更新值来重用缓存片段。

它仍然是WIP,但看起来很有希望。

Okay. I myself have found a way. I am caching the DOM fragment (without removing from body) prepared by underscore template. When next time same fragment is needed, I re-use the cached fragment by updating the values using jQuery selectors.

It is still WIP but looks promising.

更多推荐

本文发布于:2023-08-07 17:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:片段   方法   HTML   fragment   complex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!