我希望从我的 Cordova/PhoneGap 应用程序中读取这些值config.xml
在运行时:
然而,很惊讶地发现没有'Config
API 参考指南中的功能:http://cordova.apache.org/docs/en/3.4.0/index.html
我已经求助于编写自己的函数来手动读取和解析该文件,但是我觉得必须有一个(现有的)更好的方法。
开发人员是否应该手动解析 config.xml 以提取必要的信息,或者是否有现有的插件可用于执行此操作?
您可以在 iOS、WP7、WP8、Windows8 和可能的 Ubuntu 上使用以下代码
function readConfig() {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
var parser = new DOMParser();
var doc = parser.parseFromString(xhr.responseText, "application/xml");
alert("Description : " +
doc.getElementsByTagName("description").item(0).textContent);
});
xhr.open("get", "../config.xml", true);
xhr.send();
}
对于Android,你必须更改文件路径"../config.xml"
to "../../android_res/xml/config.xml"
摘自科尔多瓦邮件讨论的答案:https://www.mail-archive.com/[电子邮件受保护]/msg14313.html
还有非官方插件用于读取配置:https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)