有人在这里问了同样的问题How do you get the value from a TVML textField?,但没有解释完整的答案,我的评论被编辑,提示我问一个全新的问题。这里是...如何在TVJS中获取TVML文本字段的节点和键盘引用?
任何人都可以帮助理解如何最好地从TVML中获得对textField
节点及其键盘值的参考吗?现在,我在下面使用这段代码中Presenter.js
才能到textField
一旦用户点击该模板中Done
按钮显示形式&键盘,但仍然得到
器iTM1:未定义不是一个对象(评估'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...
...........................
UPDATE:
我找到了解决办法通过查看accessing elements by traversing 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