Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 如何更改NativeScript标签的文本_User Interface_Label_Nativescript - Fatal编程技术网

User interface 如何更改NativeScript标签的文本

User interface 如何更改NativeScript标签的文本,user-interface,label,nativescript,User Interface,Label,Nativescript,我是NativeScript新手,需要能够更改标签的文本。我不知道该怎么做,需要帮助。我该怎么做?提前谢谢 第一种方式: 您可以为要获取的标签设置id,并使用getViewById在控制器文件(即.js)中引用它: 在page.xml中: <Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded"> <Label id="myLabel" text="" /> </Page&

我是NativeScript新手,需要能够更改标签的文本。我不知道该怎么做,需要帮助。我该怎么做?提前谢谢

第一种方式:

您可以为要获取的标签设置
id
,并使用
getViewById
在控制器文件(即
.js
)中引用它:

在page.xml中:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
    <Label id="myLabel" text="" />
</Page>
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
    <Label text="{{ myText }}" />
</Page>
第二种方式:

将上下文(可观察对象)绑定到page.xml,并通过该上下文的属性之一设置标签的文本。通过这种方式,当您更改属性的值时,标签将自动更新文本:

在page.xml中:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
    <Label id="myLabel" text="" />
</Page>
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
    <Label text="{{ myText }}" />
</Page>