使用 Ext 的 update() 而不是 dom.innerHTML 的问题

发布于 2024-08-19 04:22:52 字数 684 浏览 2 评论 0原文

我有一个关于使用 Extjs 的 update() 方法的性能、可靠性和最佳实践方法的问题,与直接更新 Ext 元素的 dom 的innerHTML 相比。

考虑这两个语句:

Ext.fly('element-id').dom.innerHTML = 'Welcome, Dude!';

Ext.fly('element.id').update('Welcome, Dude!', false);

不需要 eval() 任何脚本,并且我确信 update() 会考虑任何浏览器的怪癖。


另外,有谁知道使用:

Ext.fly('element-id').dom.innerHTML

是否与 相同

d.getElementById('element-id').innerHTML


浏览器和平台兼容性很重要,如果两者本质上是相同的,那么完全放弃 Ext.element.dom.innerHTML 并使用 update() 可能是我最好的解决方案。

预先感谢您的帮助,

布莱恩

I have a question concerning the performance, reliability, and best practice method of using Extjs's update() method, versus directly updating the innerHTML of the dom of an Ext element.

Consider the two statements:

Ext.fly('element-id').dom.innerHTML = 'Welcome, Dude!';

and

Ext.fly('element.id').update('Welcome, Dude!', false);

I don't need to eval() any script, and I'm certain that update() takes into consideration any browser quirks.

Also, does anyone know if using:

Ext.fly('element-id').dom.innerHTML

is the same as

d.getElementById('element-id').innerHTML

?
Browser and platform compatibility are important, and if the two are fundamentally the same, then ditching Ext.element.dom.innerHTML altogether for update() would probably be my best solution.

Thanks in advance for your help,

Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潜移默化 2024-08-26 04:22:52

如果您不需要将脚本动态加载到更新的 html 中或在更新后处理回调,那么您概述的两种方法是等效的。 update() 中的大部分代码添加了脚本加载和回调功能。在内部,它只是设置innerHTML 来进行内容替换。

Ext.fly().dom 返回一个普通的 DOM 节点,因此,就其指向的节点而言,它相当于 getElementById() 的结果。唯一需要理解的微妙之处是 Ext.fly() 和 Ext.get() 之间的区别。 Ext.fly() 返回节点包装器对象的共享实例(享元)。因此,如果任何其他代码调用 Ext.fly()(包括内部 Ext 代码),该实例稍后可能会指向幕后的不同节点。因此,调用 Ext.fly() 的结果应该仅用于原子操作,而不应作为长期对象重用。另一方面,Ext.get().dom 返回一个新的、唯一的对象实例,从这个意义上说,它更像 getElementById()。

If you do not need to load scripts dynamically into your updated html or process a callback after the update, then the two methods you've outlined are equivalent. The bulk of the code in update() adds the script loading and callback capabilities. Internally, it simply sets the innerHTML to do the content replacement.

Ext.fly().dom returns a plain DOM node, so yes, it is equivalent to the result of getElementById() in terms of the node it points to. The only subtlety to understand is the difference between Ext.fly() and Ext.get(). Ext.fly() returns a shared instance of the node wrapper object (a flyweight). As such, that instance might later point to a different node behind the scenes if any other code calls Ext.fly(), including internal Ext code. As such, the result of a call to Ext.fly() should only be used for atomic operations and not reused as a long-lived object. Ext.get().dom on the other hand returns a new, unique object instance, and in that sense, would be more like getElementById().

迟到的我 2024-08-26 04:22:52

我想你回答了你自己的问题:“浏览器和平台兼容性很重要,如果两者本质上是相同的,那么完全放弃 Ext.element.dom.innerHTML 而使用 update() 可能是我最好的解决方案。” JS 库旨在(部分)抽象浏览器差异;更新就是一个例子。

@bmoeskau 在上面写道, update() 提供了您当前问题不需要的附加功能。不过,更新是一个不错的选择。

I think you answered your own question: "Browser and platform compatibility are important, and if the two are fundamentally the same, then ditching Ext.element.dom.innerHTML altogether for update() would probably be my best solution." JS libraries are intended (in part) to abstract browser differences; update is an example.

@bmoeskau wrote above, update() provides additional functionality that you don't need right for your current problem. Nevertheless, update is a good choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文