我正在尝试从nativescript核心的文本字段中获取文本。
let textField = args.object;
const yourSearch = textField.getViewById("requiredSkill").text;
我得到的错误是:无法读取未定义的属性'text'
请帮助
NativeScript视图XML TextView
<TextView editable="true" id="requiredSkill"></TextView>
带有tap
事件的简单按钮
<Button text="Button" tap="{{ onButtonTap }}" />
该点击事件背后的JavaScript代码
var viewModel = observableModule.fromObject({
onButtonTap: function (btargs) {
let srcButton = btargs.object;
const yourSearch = srcButton.page.getViewById("requiredSkill").text;
}
});
getViewById
应该在<Page>
模型上使用,以搜索整个页面或者您必须具有一个容器/布局,该容器/布局应具有一个ID,请首先使用getViewById
查找布局,然后再次在该布局中执行另一个getViewById
以查找TextView
因此回答您的问题,如果这是按钮单击事件,请获取按钮并获取按钮的页面并通过ID查找视图
srcButton.page.getViewById