有人在這裏問了同樣的問題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