2

誰かがここで同じ質問をしましたどうすれば TVML textField から値を取得できますか? しかし、完全な回答を説明しておらず、そこにある私のコメントが編集されたため、まったく新しい質問をするよう提案されました。ここにあります...

textFieldTVML からノードとそのキーボード値への参照を取得する最良の方法を理解できる人はいますか? 現在、以下のコードを使用してPresenter.jstextFieldユーザーがDoneフォームとキーボードを表示するテンプレートのボタンをクリックすると、

ITML : undefined はオブジェクトではありません (「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 
4

3 に答える 3

0

使用する必要があります

xmlElem.item(i)

それ以外の

xmlElem.item[i]
于 2015-11-09T10:21:30.880 に答える
0

自己説明の解決策を想定して、変更コールバックのテキストを完成させるために追加しています。

var keyboard = textField.getFeature("Keyboard");
keyboard.onTextChange = function () {
  console.log("onTextChange "+keyboard.text)
}

そして、formTemplateが次のようであると仮定します

<formTemplate>
    <banner>
      <title>${formTitle}</title>
      <description class="longDescriptionLayout">${formDescription}</description>
    </banner>
    <textField>${formPlaceholder}</textField>
    <footer>
      <button id="pairingCodeInput">
        <text>Confirm</text>
      </button>
    </footer>
  </formTemplate>

クラスでは、次のPresenterようなセレクターをさらに処理するために追加します。

if ((event.type == "select")) { // item selected
    if (itemId == "pairingCodeInput") { // form input
        var formTemplate = ele.parentNode.parentNode;
        var children = formTemplate.childNodes
        var textField = children.item(1)
        var keyboard = textField.getFeature("Keyboard")
        keyboard.onTextChange = function() {
            console.log("onTextChange " + keyboard.text)
        }
        var userValue = keyboard.text
        console.log("Entered " + userValue)

    }
}
于 2015-10-16T21:28:20.113 に答える