Javascript 在jquery函数中,如何附加对象';s值
在jquery函数中,如何附加对象。价值观 这里的student是一个对象,包含值name、admissionNo等Javascript 在jquery函数中,如何附加对象';s值,javascript,jquery,html,Javascript,Jquery,Html,在jquery函数中,如何附加对象。价值观 这里的student是一个对象,包含值name、admissionNo等 $('<td></td>').val(item['id']).html(item['student.name']) 你想用$('').val(项['id'])做什么?表格单元格没有值。共享json结构您的追加语法错误,缺少逗号。使用控制台调试代码怎么样?所以已经完成了一次编辑,删除了错误的附加语法…我喜欢这种方法。在不知道从对selectTestStu
$('<td></td>').val(item['id']).html(item['student.name'])
你想用
$('').val(项['id'])
做什么?表格单元格没有值。共享json结构您的追加语法错误,缺少逗号。使用控制台调试代码怎么样?所以已经完成了一次编辑,删除了错误的附加语法…我喜欢这种方法。在不知道从对selectTestStudent.html
的请求返回的JSON结构的情况下,这只是在黑暗中随机拍摄的,并不能帮助人们学会如何自己调试问题。@Rob Baillie:这不是随机拍摄的,你看提问者使用的是项目[“student.name”]。我的建议是这样的。我的理念是人们在尝试了很多之后才来到这里。他们从新的角度受益。他们迟早会学会的。
function onTestStudentChange() {
$.ajax({
type : 'POST',
dataType : 'json',
url : '/sample/selectTestStudent.html',
data : ({
id : $('#test').val()
}),
success : function(responseData) {
if (responseData != null) {
$('#studentTest').find('td').remove().end().append('').val('-1');
$.each(responseData,function(index, item) {
$('#studentTest').append(
$('<td></td>').val(item['id']).html(item['student.name']),
$('<tr></tr>').val(item['id']).html(item['']) );
alert("Alert"+item['student.name']);
});
} else {
$('#studentTest').find('td').remove().end().append(
'<td th:text="${student}"></td>').val('-1');
}
}
});
}
{"id":1,"student":{"id":51,"name":"Nimal","fatherName":"Adhithya","motherName":"Anila","admissionNo":"002","division":{"id":4,"divisionName":"B","standardId":{"id":7,"standardName":"LPKG","schoolId":{"schoolId":3,"schoolCode":"003","schoolName":"CMSHSS","schoolAddress":"TSR","schoolStreet":"Round south","schoolCity":"Thrissur","district":{"districtId":1,"districtName":"Thrissur","state":{"id":1,"stateName":"KERALA","country":{"countryId":10,"countryName":"INDIA","createdDate":"Oct 3, 2013","isDelete":false},"createdDate":"Aug 19, 2013","isDelete":false},"createdDate":"Aug 19, 2013","isDelete":false},"state":{"id":1,"stateName":"KERALA","country":{"countryId":10,"countryName":"INDIA","createdDate":"Oct 3, 2013","isDelete":false},"createdDate":"Aug 19, 2013","isDelete":false},"country":{"countryId":10,"countryName":"INDIA","createdDate":"Oct 3, 2013","isDelete":false},"schoolPhone":"1204536789","schoolEmail":"cms@ymail.com","schoolFax":"9876543210","status":false,"createdDate":"Dec 12, 2013","isDelete":false},"createdDate":"Aug 20, 2013","isDelete":false},"createdDate":"Aug 24, 2013","isDelete":false},"phoneNo":9804758123,"status":false,"createdDate":"Dec 18, 2013 12:00:00 AM","isDelete":false},"test":{"id":1,"testName":"Numbers","createdDate":"May 9, 2013 12:00:00 AM","isDelete":false},"correct":10,"wrong":0,"notAttend":0,"mark":100,"max_mark":100,"attendDate":"Dec 12, 2013 12:00:00 AM","createdDate":"Dec 12, 2013 12:00:00 AM","IsDelete":false}" ViewReport.html:162
var student = item["student"];
if(student) {
var name = student["name"];
}