How to render imported xml through js?

nativescriptcore

#1

Hi all,

I created an xml file in some other folder and imported as
<Page xmlns:calculatorLayout="views/calculators/calculators-layouts"/>

I want to create an tab element and add imported xml as child to Tabelement.

var tabEntry1 = new tabViewModule.TabViewItem();
tabEntry1.view = ------Our imported file

Is it possible


#2

Of course you can import a custom component built using XML from JS with builder.

var builder = require("ui/builder");
var myComponentInstance = builder.load({
        path: "~/xml-declaration/mymodule",
        name: "MyControl"
});

for more info - https://docs.nativescript.org/ui/basics


#3

@manojdcoder

Thats is correct but my existing tap events and other bindings are not working on imported xml file.

Do I need to add seperate js file to that xml file?


#4

Yes, builder processes the XML stuffs and returns the JS instance. So if you never had a JS part for your module but just event names mentioned in XML it will never find the callback functions for binding.

You may add your listeners once instance is created / handle them in separate JS file as you always can pass in the binding context and get access to all data.