【发布时间】:2020-07-17 18:36:26
【问题描述】:
我正在学习使用 NativeScript (Angular 2) 制作应用程序。在我的项目页面中,我想要一个按钮,以便当我按下它时,我可以将 Label 更改为 TextView/TextField 以编辑项目的信息。
我知道我可以在 TextView 中使用 editable,但我仍然想知道让按钮具有该功能是否可行。谢谢!!
item.component.html:
<StackLayout>
<Label class="h3" text="Name: {{ item.get_name() }}" textWrap="true">
</Label>
<Label class="h3" text="Credit: {{ item.get_credit() }}"></Label>
<Button class="btn" text="Edit" (tap)="change()"></Button>
</StackLayout>
<!-- After pressing the button -->
<StackLayout>
<TextView class="h3" [text]="item.get_name()" textWrap="true">
</TextView>
<TextView class="h3" [text]="item.get_credit()"></TextView>
<Button class="btn" text="Save" (tap)="change()"></Button>
</StackLayout>
【问题讨论】:
-
对于这样的事情,我通常只是改变控件的可见性。例如,您可以有一个覆盖标签的文本字段(可能需要一个 GridLayout 来执行此操作)。点击按钮将隐藏标签并显示文本字段,并且两者都可以绑定到同一个变量。
标签: nativescript