有人在这里提出同样的问题How do you get the value from a TVML textField?,但没有解释完整的答案,我的评论已被编辑,建议我提出一个全新的问题。这是......
任何人都可以帮助了解如何最好地从TVML获取对<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.arion.arionbookeeper"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.RECORD_AUDIO"
android:required="true" />
<uses-permission
android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission
android:name="android.permission.MODIFY_AUDIO_SETTINGS"
android:required="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".WallPApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBar"
tools:replace="android:theme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<service
android:name=".eventListeners.BackgroundEventListenerService"
android:exported="false"
android:icon="@drawable/ic_launcher" />
<activity
android:name=".GettingStarted"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Rest of activites -->
</application>
</manifest>
节点及其键盘值的引用吗?现在,我在textField
中使用此代码,一旦用户点击显示表单&amp;表格的模板中的Presenter.js
按钮,即可转到textField
。键盘,但仍然得到
ITML:undefined不是对象(评估'textField.getFeature') - ... / js / Presenter.js
当我使用Done
时:
getFeature("Keyboard")
更新:
我通过查看accessing elements by traversing XML DOM找到了解决方案:
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...
...........................
答案 0 :(得分:1)
从文档的根开始怎么样?使用getElementsByTagName
,getElementByTagName
或getElementById
访问textField
。
var doc = navigationDocument.documents[navigationDocument.documents.length-1];
var textField = doc.getElementByTagName("textField")
var value = textField.getFeature("Keyboard").text;
答案 1 :(得分: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)
}
}
答案 2 :(得分:0)
您需要使用
xmlElem.item(i)
而不是
xmlElem.item[i]