问题
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>
I want to get tag element FormattedString by his id - formString In javascript is like this:
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.
回答1:
Use Label.getViewById("formString")
to access the attributes of FormattedString.
getViewById is the nearest equivalent to the javascript getElementById
Hope this helps
来源:https://stackoverflow.com/questions/56316914/how-to-get-elementbyid-in-nativescript