我想重用我使用下划线模板创建的复杂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.
更多推荐
发布评论