thi*_*all 11 xml config cordova
我希望config.xml在运行时从Cordova/PhoneGap应用程序中读取这些值:
但是,令人惊讶的是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();
}
Run Code Online (Sandbox Code Playgroud)
对于Android,您必须将路径更改"../config.xml"为"../../android_res/xml/config.xml"
取自Cordova邮件,其中讨论了答案:https: //www.mail-archive.com/dev@cordova.apache.org/msg14313.html
还有用于阅读配置的非官方插件:https: //github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
| 归档时间: |
|
| 查看次数: |
8566 次 |
| 最近记录: |