javascript - 如何在 nativescript 中获取文本字段值
问题描述
我正在尝试从 nativescript 核心中的文本字段中获取文本。
let textField = args.object;
const yourSearch = textField.getViewById("requiredSkill").text;
我得到的错误是:无法读取未定义的属性“文本”
请帮忙
解决方案
NativeScript 视图 XMLTextView
<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
推荐阅读
- python - 这两行如何工作 x2 = x+delta[i][0] , y2 = y+delta[i][1]?
- angularfire2 - Firestore 的 WriteBatch.update() 不会占用 angularfirestore2 的 AngularFirestoreDocument
- mongodb - 带有聚合管道的 mongodb 更新操作导致错误代码 14
- ios - 映射字典数组中特定键的值
- java - 列表未更新的应用小部件 - 为什么会这样?
- android - 无法将 DialogPreference 与 androidx 一起使用
- python - Python / XML结束标记错误 - 无法解析
- php - 将应用程序注册到 URL
- javascript - 如何删除半图像卡并使其充满html,css
- angular - Angular:订阅未检测到更改,因此我的视图未更新