在 Nativescript 中创建组件的正确方法是什么?

What is a proper way to create component in Nativescript?

Nativescript 中创建自定义模板的正确方法是什么?

例如我的 XML 结构如下:

     <FlexboxLayout flexDirection="column" alignItems = "stretch">
        <Border  borderWidth="1" borderColor="#000000">
        <FlexboxLayout height="60">
            <Button cssClass="sdk-button" col="0" text="initSDK" tap="{{initSdk}}" flexGrow="1"/>

            <StackLayout orientation="horizontal" class="data-wrapper" flexGrow="3" paddingLeft="20">
                <Label text="{{ initSdkResponse }}" class="data_wrapper-label" textWrap="true"/>
            </StackLayout>
        </FlexboxLayout>
        </Border>
    </FlexboxLayout>

我想创建具有上述结构的组件,命名为 MyItem 并按如下方式使用它:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
    <StackLayout orientation="vertical">
      <MyItem buttonName="click1"
              buttonAction="onClick1()"
              labelText="xxxxxxx1"
      ></MyItem>

      <MyItem buttonName="click2"
              buttonAction="onClick2()"
              labelText="xxxxxxx2"
      ></MyItem>
    </StackLayout>
</Page>

我认为这些资源会对您有所帮助:

https://moduscreate.com/custom-components-in-nativescript/

http://blog.bradleygore.com/2016/03/12/custom-nativescript-components/

http://docs.nativescript.org/ui/basics#custom-components