当触发一个文本字段textChange并将一些内容替换或添加到绑定的字符串时,光标将转到Start(在带有NativeScript 5.0 Core的Android中(。这是代码:
page.getViewById("productPrizeTextField")
.addEventListener("textChange", function () {
if(mv.productPrize.includes('.')) {
mv.productPrize = mv.productPrize.replace(".", ",");
}
validation();
})
我发现这是一个问题,但有什么方法可以欺骗光标移动到最后吗?
这是Android的默认行为。解决方法是在本机文本视图上调用setSelection
方法。
....
mv.productPrize = mv.productPrize.replace(".", ",");
if (args.object.android) {
// Where 'args' is argument passed to textChange event
args.object.android.setSelection(mv.productPrize.length);
}
...