【发布时间】:2018-01-25 04:37:54
【问题描述】:
我现在正在开发一个致力于本地化的混合应用程序,其逻辑是用户将拥有例如 3 个选择语言的选项,我在 bluemix 上有一个 node.js 服务器来处理 cloudant-nosql db开始吧,我将我的本地 json 文件“rev”值与服务器上的另一个值进行比较,如果它们不同,那么我必须用更新的文件覆盖本地文件,我有这个结果,但我无法将此数据写入本地文件,我现在正在使用 cordova 和 ionic 2 ,
public GetRevFromNode(SelectedLanguage,JsonDataLocal)
{
JsonDataLocal.subscribe(val=>{ this.LocJson=val; })
this.http.get('https://*********/retriev?ID=\"'+SelectedLanguage+"\"").subscribe( result=>
{
if(this.LocJson['_rev']==result.json().value)
{
console.log("The Local Json is Updated to the latest");
return ;
}
{
console.log("Updating Json File for "+SelectedLanguage+".json .......");
var ob=this.file.readAsText(this.file.applicationDirectory+'www/assets/i18n',"ar.json");
ob.then(function(val){
console.log("ar JSON = "+val);
});
this.file.createFile('file:///android_asset/www',"ess.json",true).catch(val=>{
console.log("Can't create because = "+JSON.stringify(val));
});
this.file.writeFile('file:///android_asset/www/',"index.html","\"value\":\"Please\"",{replace:true , append:false} ).catch(val=>{
console.log("Can't write because ="+JSON.stringify(val));
console.log("Updating Done ...")
}
} );
}
试图使用this.file.appDirectory错误也试图让它像这里一样隐式
错误是
未捕获的承诺 [object Object]
通过使用 stringify {Code:1000}
但我可以正常读取并检查文件是否正常存在,问题在于创建和写入
【问题讨论】:
标签: javascript android ionic2 ngcordova ionic-native