4

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.

stanimirsp
  • 2,548
  • 2
  • 26
  • 36

1 Answers1

5

Use Label.getViewById("formString") to access the attributes of FormattedString.

getViewById is the nearest equivalent to the javascript getElementById

Hope this helps

Community
  • 1
  • 1
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
  • 1
    e.g. Label.getViewById(“formString”).backgroundColor would return yellow.. – Rachel Gallen May 26 '19 at 20:28
  • 2
    This totally works but still if you are on Vue, then using `ref` instead of `id` may be preferred. – Manoj May 26 '19 at 21:06
  • 1
    @RachelGallen thanks for the fast answer. I was able to get element by this way: `getElemBg(args) { const view = require("tns-core-modules/ui/core/view"); let button = args.object; let parent = button.parent; let fstr = view.getViewById(parent, "formString"); fstr.backgroundColor; }` – stanimirsp May 27 '19 at 19:17