2013-06-12 64 views
0

我正在用jquerymobile构建一个应用程序,并且我有一个页面,这是一个表单,我必须填写一些有关我所做的字段工作的信息,因此我可以保存它到达商店并通过猜测到达时间和完成时间来填写文件。 所以,我想填写表格,当我点击提交时,它会在android手机上保存一个txt或另一种文件类型。 感谢JQueryMobile将表单保存到txt文件

回答

0

这个工作对我来说...

当用户点击如果你想恢复保存按钮

var form_1; 
var jsonString; 
function saveFormState() { 
     form_1 = $("#form").find("select,textarea, input").serializeArray(); 
     jsonString = JSON.stringify(form_1); 
     console.log(jsonString); 

     getFSToSaveForm(); 
} 

function getFSToSaveForm(){ 
     window.requestFileSystem(LocalFileSystem.PERSISTENT,0 ,function(fileSystem){ 
      var entry=fileSystem.root; 
       entry.getDirectory('myForms', {create:true, exclusive:false}, function(dirEntry){ 
        dirEntry.getFile('formToSave.json', { create: true, exclusive: false}, saveToJsonFile, onError); 

       }, onError); 
     }, onError); 
    } 

    function saveToJsonFile(fileEntry){ 
     fileEntry.createWriter(function(writer){ 
      writer.onwrite = function (evt) { 
       console.log("Wrote to file: " + jsonString); 
      }; 
      writer.write(jsonString); 
     }, onError); 
    } 

: +阅读该文件并保存在vaiable 读取文本然后使用一些Jquery。

var jsonString; 
function getFSToRead(){} //You can find the code in the cordova API http://cordova.apache.org/docs/en/2.5.0/cordova_file_file.md.html 

function restoreFormState() { 
    var newObjectArray ; 
    newObjectArray = JSON.parse(jsonString); 

     console.log(newObjectArray.length); 
     jQuery.each(newObjectArray, function(i, field) { 
     $('#' + field.name).val(field.value); 
     });  
} 

希望帮助