如何在Nativescript中获取elementById? [英] How to get elementById in Nativescript?
问题描述
我正在将nativescript与vue.js一起使用,并且正在尝试执行类似DOM操作的操作.这是我的模板中的示例代码:
I'm using nativescript with vue.js and I'm trying to do something like DOM operation. This is sample code from my template:
<Label textWrap="true">
<FormattedString id="formString"
backgroundColor="yellow"
effectiveHeight="100"
effectiveWidth="100%">
<Span text="This text has a " />
</FormattedString>
</Label>
我想通过他的ID- formString 获得标签元素 FormattedString 在javascript中是这样的:
I want to get tag element FormattedString by his id - formString In javascript is like this:
让fs = doument.getElementById('formString');
如何在Nativescript-Vue中做到这一点?我知道有一个库 nativescript-dom ,但是我不想使用整个库,用于简单的getById.
let fs = doument.getElementById('formString');
How can I do this in Nativescript-Vue?
I know that there is library nativescript-dom, but I don't want to use whole library for simple getById.
推荐答案
使用 Label.getViewById("formString")
访问FormattedString的属性.
Use Label.getViewById("formString")
to access the attributes of FormattedString.
getViewById 与javascript getElementById最接近
getViewById is the nearest equivalent to the javascript getElementById
希望这会有所帮助
这篇关于如何在Nativescript中获取elementById?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!