在 Oyeme 的建议下,我更改了代码,但仍然无法工作。它可以提醒“测试”,但不能提醒 DBuser_name 。
通过以下编码,我可以创建如下图所示的内容。我的问题是,如果用户单击列表中的一个人,我想将其提取 student.data.user_name
到 localStorage。但是,在我下面的编码中,似乎我做错了?
function getStudentList() {
$.getJSON('http://mydomain.com/getStudents.php?jsoncallback=?', function(data) {
$('#studentList li').remove();
$('#load').hide();
//students = data.user_name;
$.each(data, function(index, student) {
//$('#studentList').append('<li><a href="tutor_student_detail.html?user_name=' + student.data.user_name + '">' +
$('#studentList').append('<li><a href="tutor_student_detail.html">' +
'<h4>' + student.data.user_name + '</h4>' +
'<p>' + student.data.role + '</p>' +
'</a></li>');
$("li a").click(function() {
window.localStorage["view"] = $(this).data('user_name');
});
});
$('#studentList').listview('refresh');
});
}
以下是tutor_student_detail.html(js部分)的编码
function start(){
var localUsername=window.localStorage.getItem("view");
$.getJSON('http://mydomain.com/getStudent.php?user_name='+localUsername+'&jsoncallback=?', displayStudent);
alert("testing");
}
function displayStudent(data) {
var DBuser_name=data[0].data.user_name;
alert(DBuser_name);
var employee = data.item;
$('#username').text(student.data.user_name);
$('#pw').text(student.data.password);
$('#id').text(student.data.id);
$('#actionList').listview('refresh');
}
json字符串的输出类似于
?([{"data":{"id":"4","user_name":"studentB","book":"4567","role":"Student"}}]);