//插入N条数据 function setItemFun( id ) {
//循环插入100调数据
var dataNum = new Number(id);
for ( var i=0; i<dataNum; i++ ) {
plus.storage.setItem( "key"+i, "value"+i );
}
var length = getLengthFun();
outSet( "数据存储成功,存储了"+length+"条数据;" );
}
function getLengthFun(){
return plus.storage.getLength();
} //查询所有数据
function getAllItem(){
outSet( "获取数据:" );
var itemLength = getLengthFun();
for ( var i=0; i < itemLength; i++ ) {
var key = plus.storage.key(i);
var value = plus.storage.getItem(key);
outLine( "key:"+key+"-->value:"+value );
};
} //删除部分Item
function delItem() {
outSet( "删除数据:" );
var itemLength = getLengthFun();
for (var i=0; i < itemLength; i+=2) {
var key = plus.storage.key(i);
plus.storage.removeItem(key);
};
var itemNo = getLengthFun();
outLine( "移除了"+(itemLength-itemNo)+"条数据" );
} //清除所有内容
function clearAllItem(){
plus.storage.clear();
var num = getLengthFun();
if ( num == 0 ) {
outSet( "storage数据清除成功!" );
}else{
outSet( "storage数据清除失败!" );
}
} //修改前五条数据的内容
function modifyTopFive(){
outSet( "修改前的数据是:" );
for (var i=0; i < 5; i++) {
var key = plus.storage.key(i),value = plus.storage.getItem(key);
outLine( "key:"+key+"-->value:"+value );
plus.storage.setItem( key, "新数据值>>"+i );
};
outLine( "修改后的数据是:" );
for (var i=0; i < 5; i++) {
var key = plus.storage.key(i),value = plus.storage.getItem(key);
outLine( "key:"+key+"-->value:"+value );
};
}