有人在这里问了同样的问题How do you get the value from a TVML textField? 但没有解释完整的答案,我的评论已被编辑,建议我提出一个全新的问题。这里是...
任何人都可以帮助了解如何最好地textField
从 TVML 获得对节点及其键盘值的引用吗?现在,我正在使用下面的代码Presenter.js
来访问textField
一旦用户单击Done
模板中显示表单和键盘的按钮,但仍然得到
ITML:未定义不是对象(评估'textField.getFeature') - .../js/Presenter.js
当我使用getFeature("Keyboard")
:
load: function(event) {
var self = this,
ele = event.target,
templateURL = ele.getAttribute("template"),
presentation = ele.getAttribute("presentation"),
videoURL = ele.getAttribute("videoURL");
if (templateURL && (event.type == "select")) {
var formTemplate = ele.parentNode.parentNode; // that should give me <formTemplate> element
var children = formTemplate.childNodes;
var textField = children[1]; // which is the second element in <formTemplate><banner></banner><textField></textField>...
var keyboard = textField.getFeature("Keyboard"); // this raises the ITML Error...
...........................
更新:
我通过遍历 XML DOM查看访问元素找到了解决方案:
var formTemplate = ele.parentNode.parentNode; // your formTemplate button
var children = formTemplate.childNodes;
var textField = children.item(1); // replace "1" with the index of "textField" element in your template
var keyboard = textField.getFeature("Keyboard"); // get the textField's Keyboard element
var userValue = keyboard.text; // the value entered by the user on the Apple TV keyboard