.mui-content {
margin-top: 10px;
}
.mui-input-group .mui-input-row {
height:50px;
}
.mui-input-group .mui-button-row{
height:50px;
padding-top:8px;
}
K-V
首页
车牌
密码
var json;
document.addEventListener( "plusready", onPlusReady, false );
function onPlusReady() {
plus.io.requestFileSystem( plus.io.PUBLIC_DOCUMENTS, function( fs ) {
fs.root.getFile("ofo.json",{create:true,exclusive:false}, function(fileEntry){
fileEntry.file( function(file){
var fileReader = new plus.io.FileReader();
fileReader.readAsText(file, 'utf-8');
fileReader.onloadend = function(evt) {
json=evt.target.result;
console.log(json);
}
} );
});
}, function ( e ) {
mui.toast( "Request file system failed: " + e.message );
} );
}
function jsonWriter(newJson){
plus.io.requestFileSystem( plus.io.PUBLIC_DOCUMENTS, function( fs ) {
fs.root.getFile("ofo.json",{create:false,exclusive:false}, function(fileEntry){
fileEntry.createWriter( function ( writer ) {
writer.onwrite = function ( e ) {
plus.console.log( "Write data success!" );
};
writer.seek( 0 );
writer.write( newJson);
}, function ( e ) {
mui.toast( "Resolve file URL failed: " + e.message );
} );
});
}, function ( e ) {
mui.toast( "Request file system failed: " + e.message );
} );
}
mui.plusReady(function(){
document.getElementById("save").addEventListener("tap",function(){
var ofo_key=document.getElementById("ofo_key").value.trim();
var ofo_value=document.getElementById("ofo_value").value.trim();
if(!ofo_key && !ofo_value){
mui.toast("key-value不能为空");
return ;
}
var obj;
if(!json){
obj=new Object();
}else{
obj=JSON.parse(json);
}
obj[ofo_key]=ofo_value;
var str =JSON.stringify(obj);
json =str;
jsonWriter(str);
mui.toast("成功保存");
});
document.getElementById("get").addEventListener("tap",function(){
var ofo_key=document.getElementById("ofo_key").value.trim();
if(!ofo_key){
mui.toast("key不能为空");
return ;
}
var obj=JSON.parse(json);
var value =obj[ofo_key];
if(!value){
mui.toast("不存在该车牌");
return ;
}
document.getElementById("ofo_value").value=value;
///mui.toast(value);
});
document.getElementById("back").addEventListener("tap",function(){
window.location.href="index.html";
});
})
一键复制
编辑
Web IDE
原始数据
按行查看
历史