0
我試着創建一個配置文件來保留我的應用程序的一些配置。我正在使用SAPUI5和cordova文件。SAPUI5使用cordova文件創建配置文件
目的是創建一個conf.txt來保持URL,PORT和LDAP數據訪問我的系統。但是,這些信息可能會改變,所以我需要更新文件。
在我的應用程序,我所做的功能deviceready應用程序啓動時,創造了conf.txt:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
/*jQuery.sap.require("model.Config");
var conf = new Configuration();
conf.init();*/
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("conf.txt", {create : true,exclusive : false},gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
//alert(fileEntry.fullPath);
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
alert("OK");
};
var conf = "URL=\r\nPORT=80\r\nLDAP=false";
writer.seek(writer.length);
writer.write(conf);
}
function fail(error) {
alert(error.code);
}
我沒有做什麼其他的例子不同。但是,正如我在onDeviceReady
函數中所評論的那樣,我試圖創建一個類來創建文件,讀取和更新它。
我找到的所有例子都引用了deviceready事件。我可以在這個事件上使用FileWriter和FileReader的方法嗎?
這是我的配置類:
function Configuration() {
this.fileName = "conf.txt";
this.init = function() {**How to use the cordova API here**};
this.read = function(){**How to use the cordova API here**};
this.update= function(){**How to use the cordova API here**};
}
感謝您的幫助!
您是否可以在捆綁應用程序時將這些值存儲在.json文件中?就值的變化而言,您可以將新值存儲在本地存儲中。這個策略似乎比擔心在文本文件中保存文件系統的值簡單得多。 – njtman 2015-02-23 17:43:04
謝謝njtman!很有幫助 – mayconbelfort 2015-02-24 23:26:07