我正在开发一个 PhoneGap 应用程序,在该应用程序中我保存了用户的姓名、号码和电子邮件,之后我将该数据显示到列表视图中的另一个页面。这已经非常成功地完成了。但是现在当我想将用户的图像存储在本地存储中时,我得到的是图像的路径而不是图像。
我以这种方式保存我的数据:
<SCRIPT Language="JavaScript" charset="utf-8" type="text/javascript">
var userName, userNumber, userEmail, userImage ;
function showAndClearField(frm)
{
userName = frm.name.value;
userNumber = frm.number.value;
userEmail = frm.email.value;
if (frm.name.value == "" )
{
alert("Please enter your name!")
}
else if(frm.number.value == "")
{
alert("Please enter your number!")
}
else if(frm.email.value == "")
{
alert("Please enter your Email !")
}
else
{
alert("Name : " + userName + '\n' + " Number: " + userNumber + '\n' + " Email: " + userEmail )
frm.name.value = ""
frm.number.value = ""
frm.email.value = ""
var db = window.openDatabase("TestingDemo", "1.0", "PhoneGapTesting Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx)
{
tx.executeSql('INSERT INTO DEMO (id, data, userName, userNumber, userEmail, userImage) VALUES (1, "Third row", "'+ userName +'" , "'+ userNumber +'" , "'+ userEmail +'", "'+ userImage +'")');
}
在显示数据时,我使用以下代码:
var nameOfUser , numberOfUser , emailOfUser, imageOfUser;
for (var i=0; i<len; i++)
{
nameOfUser = results.rows.item(i).userName;
numberOfUser = results.rows.item(i).userNumber;
emailOfUser = results.rows.item(i).userEmail;
imageOfUser = results.rows.item(i).userImage;
numArr.push({ name : nameOfUser , number : numberOfUser , email : emailOfUser, image : imageOfUser });
}
function createCheckboxes(){
$("#createBtn").remove();
$("#content").append('<fieldset id="cbFieldSet" data-role="controlgroup" style = "padding : 20px" >');
var length = numArr.length;
for(var i=0;i<length;i++)
{
$("#cbFieldSet").append('<input type="checkbox" name= "cb-'+i+'" id="cb-' + i +'" number = "'+numArr[i].name+'"/> <label for= "cb-'+i+'">' + "Name : " + numArr[i].name + ' <br>' + "Email : " + numArr[i].email +' <br>' + " Number " + numArr[i].number +' <br>' + numArr[i].image + ' <br><br> </label>' );
alert("List Created !");
}
alert("Out of For loop !");
$("#content").trigger("create");
alert("Content Created !");
$("#showBtn").css("visibility","visible");
}
function showSelectedNames(){
var count = $("#cbFieldSet input:checked").length;
var str = '';
for(i=0;i<count;i++){
str += ' '+$("#cbFieldSet input:checked")[i].value;
}
alert("You selected----"+str);
}
</script>
我得到的观点是: