首页 > 解决方案 > NativeScript TextView:textTransform 无法更新

问题描述

我将 NativeScript 与 Vue.js 一起使用。我在 TextView 中有一些文本,我正在尝试使用 textTransform 属性将该文本从“无”更改为“大写”。这是我的示例代码,这里来自 ns 操场

<template>
    <Page class="page">
        <ActionBar title="Home" class="action-bar" />
        <ScrollView>
            <StackLayout>
                <TextView editable="false" :fontSize="textFontSize"
                    :textTransform="upperCaseText">
                    <FormattedString>
                        <Span text="This is a text view that uses attributed text. You can use text attributes such as " />
                    </FormattedString>
                </TextView>
                <Button text="Make uppercase" @tap="toUpperCase" />
            </StackLayout>
        </ScrollView>
    </Page>
</template>
<script>
    export default {
        data() {
            return {
                upperCaseText: "none",
                textFontSize: 20
            };
        },
        methods: {
            toUpperCase() {
                this.upperCaseText = "uppercase";
                this.textFontSize = 67;
            }
        }
    };
</script>

当我单击Make uppercase按钮​​时,属性upperCaseText"none"更改为"uppercase" ,但TextView未注册该更改,并且显示的文本未更改。

我试图从ns“dom”更改upperCaseText属性,试图以某种方式触发TextView上的事件并“告诉”某些事情已经改变,但没有成功。

有趣的是,当我尝试更改文本的fontSize时。没有问题,fontSize明显改变了,但textTransform没有。

为什么会这样?为什么fontSize没有问题,但textTransform不起作用?以及如何让它发挥作用?

标签: androidnativescriptnativescript-vue

解决方案


由于 Android 的限制,更新文本转换属性不会对已在 TextField / TextView 上设置的文本产生任何影响。更多信息可以在相关的Github 问题中找到。

文本字段和文本视图 (Android)

在这些控件上设置 text-transform 属性不会更改其中的文本。如果您想转换文本,您应该在将其设置为 text 属性之前进行。

我不确定您为什么将 TextView 设为只读(可编辑 =“false”),如果您不想要可编辑的 TextView,那么您可以简单地使用应该支持动态更新文本转换的标签。


推荐阅读