我将 NativeScript 与 Vue.js 结合使用。我在 TextView 中有一些文本,我试图通过使用 textTransform 属性将该文本从“无”更改为“大写”。 这是我的示例代码和 here来自ns playground
<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 已从“无”更改 到 “大写”,但 TextView 未注册此更改,并且显示的文本未更改。
我试图从 ns“dom”更改 upperCaseText 属性,尝试以某种方式触发 TextView 上的事件并“告诉“有些事情发生了变化,但没有成功。
有趣的是,当我尝试更改文本的fontSize 时。没有问题,fontSize 明显改变了,但是 textTransform 没有。
为什么会这样?为什么 fontSize 没有问题,而 textTransform 却不起作用?以及如何让它发挥作用?
最佳答案
由于 Android 的限制,更新文本转换属性不会对已在 TextField/TextView 上设置的文本产生任何影响。更多信息可以在相关的 Github issue 中找到.
TextField & TextView (Android)
Setting text-transform property on these controls will not change the text inside them. In case you want to transform the text you should do it before setting it to text property.
我不确定您为什么将 TextView 设置为只读 (editable="false"),如果您不想要可编辑的 TextView,那么您可以简单地使用一个应该支持动态更新文本转换的标签。
关于android - NativeScript TextView :textTransform can't update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56516387/