問題使用Ext的update()而不是dom.innerHTML

[英]Question using Ext's update() instead of dom.innerHTML


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.

我有一個關於使用Extjs的update()方法的性能,可靠性和最佳實踐方法的問題,而不是直接更新Ext元素的dom的innerHTML。

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.

我不需要eval()任何腳本,我確信update()會考慮任何瀏覽器怪癖。


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.

?瀏覽器和平台的兼容性非常重要,如果兩者基本相同,那么對於update()完全放棄Ext.element.dom.innerHTML可能是我最好的解決方案。

Thanks in advance for your help,

在此先感謝您的幫助,

Brian

布賴恩

2 个解决方案

#1


4  

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.

如果您不需要動態地將腳本加載到更新的html中或在更新后處理回調,那么您概述的兩種方法是等效的。 update()中的大部分代碼添加了腳本加載和回調功能。在內部,它只是設置innerHTML來進行內容替換。

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().

Ext.fly()。dom返回一個普通的DOM節點,所以是的,它相當於getElementById()的結果,就其指向的節點而言。要理解的唯一微妙之處是Ext.fly()和Ext.get()之間的區別。 Ext.fly()返回節點包裝器對象(flyweight)的共享實例。因此,如果任何其他代碼調用Ext.fly(),該實例可能稍后指向幕后的不同節點,包括內部Ext代碼。因此,調用Ext.fly()的結果應僅用於原子操作,而不能作為長期存在的對象重用。另一方面,Ext.get()。dom返回一個新的唯一對象實例,從這個意義上講,它更像是getElementById()。

#2


2  

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.

我想你回答了自己的問題:“瀏覽器和平台兼容性非常重要,如果兩者基本相同,那么完全放棄Ext.element.dom.innerHTML以獲得更新()可能是我最好的解決方案。” JS庫(部分)用於抽象瀏覽器差異;更新就是一個例子。

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

@bmoeskau在上面寫道,update()提供了您不需要的當前問題的其他功能。不過,更新是一個不錯的選擇。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/01/22/72f87ae101d659ba4b544b604a7d5a50.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com