How do you get the value from a TVML textField?

牧云@^-^@ 提交于 2019-12-11 03:33:42

问题


I am trying to figure out how to get the value from the textField in TVML using TVJS but I haven't found any documentation on it yet and I don't want to wait around for the documentation to be updated. There isn't really any patterns for binding to input since I'm sure this is a seldom use case other than logging into a service. I guess I could parse the Xml but that seems super hacky.


回答1:


I ended up figuring it out myself. I had to use the callback from the select event object and then pass the text element into a function to handle the event.

function template() {
    var template = "<document><formTemplate><textField id="email">Your email</textField><footer><button><text>Submit</text></button></footer></formTemplate></document>";
    var parser = new DOMParser();
    var doc = parser.parseFromString(template , "application/xml");
    var email = doc.getElementById("email");
    doc.addEventListener("select", function() { submit(email); });
}

function submit(textField) {
    var keyboard textField.getFeature('Keyboard');
    var email = keyboard.text;
}

Once I had the node I used the apple TVJS function getFeature('Keyboard') to get the text value from this object.




回答2:


this solution doesn't work for me by some reason, but I found another one:

 var sender = event.target;
 var formTemplate = sender.parentNode.parentNode;
 var children = formTemplate.childNodes;
 var textField = children.item(1); // replace "1" with the index of "textField" element in your template                                                                                        
 var inputValue = textField.getFeature("Keyboard").text;


来源:https://stackoverflow.com/questions/32655635/how-do-you-get-the-value-from-a-tvml-textfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!