问题描述
在我必须访问控件值的两个选项中,哪个选项最有效?
Of the two choices I have to access the value of a control which is the most efficient?
getComponent("ControlName").getValue();
或
dataSource.getItemValue("FieldName");
我发现有时 getComponent
似乎没有返回当前值,但访问 dataSource
似乎更可靠.那么从性能的角度来看,使用哪一个有很大区别吗?
I find that on occasion the getComponent
does not seem to return the current value, but accessing the dataSource
seems to be more reliable. So does it make much difference from a performance perspective which one is used?
dataSource.getValue 似乎在我尝试过的任何地方都有效.但是,在使用 rowData 时,我似乎仍然需要执行 rowData.getColumnValue("Something").rowData.getValue("Something") 失败.
The dataSource.getValue seems to work everywhere that I have tried it. However, when working with rowData I still seem to need to do a rowData.getColumnValue("Something"). rowData.getValue("Something") fails.
推荐答案
两者都不是.最快的语法是dataSource.getValue("FieldName")
.getItemValue
方法仅对文档数据源可靠,而 getValue
方法不仅可用于通过视图数据源访问的视图条目(尽管在该上下文中您会将视图列的编程名称传递给它,该名称不一定与字段名称相同),但也可用于您开发或安装的任何自定义数据源(例如第三方扩展库).此外,如果您使用 getItemValue
代替,它会自动进行类型转换.
Neither. The fastest syntax is dataSource.getValue ("FieldName")
. The getItemValue
method is only reliable on the document data source, whereas the getValue
method is not only also available on view entries accessed via a view data source (although in that context you would pass it the programmatic name of a view column, which is not necessarily the same name as a field), but will also be available on any custom data sources that you develop or install (e.g. third-party extension libraries). Furthermore, it does automatic type conversion that you'd have to do yourself if you used getItemValue
instead.
即使在非常简单的页面上,dataSource.getValue("FieldName")
的速度也是 getComponent("id").getValue()
的 5 倍,因为,正如 Fredrik 所提到的,首先它必须找到组件,然后询问它的值是什么......在幕后,它只是询问数据源.因此,自己询问数据源总是更快.
Even on very simple pages, dataSource.getValue ("FieldName")
is 5 times as fast as getComponent ("id").getValue ()
, because, as Fredrik mentions, first it has to find the component, and then ask it what the value is... which, behind the scenes, just asks the data source anyway. So it will always be faster to just ask the data source yourself.
注意:对应的写方法是dataSource.setValue("FieldName", "NewValue")
,而不是dataSource.replaceItemValue("FieldName", "新值")
.两者都可以工作,但 setValue
也进行与 getValue
相同的类型转换,因此您可以将不严格符合旧 Domino Java API 的数据传递给它通常只是弄清楚需要将值转换为什么,以便 Domino 存储安全".
NOTE: the corresponding write method is dataSource.setValue ("FieldName", "NewValue")
, not dataSource.replaceItemValue ("FieldName", "NewValue")
. Both will work, but setValue
also does the same type conversion that getValue
does, so you can pass it data that doesn't strictly conform to the old Domino Java API and it usually just figures out what the value needs to be converted to in order to be "safe" for Domino to store.
这篇关于访问控件值的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!