在jquery函数中如何附加对象的值
Inside jquery function how to append an object's value
在jquery函数内部如何附加一个对象。
这里学生是一个包含值名称、录取号等的对象。
$('<td></td>').val(item['id']).html(item['student.name'])
运行代码时,不显示 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');
}
}
});
}
Json 值:
{"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"];
}
相关文章:
- 将事件附加到对象/数组
- 在创建对象后附加一个jquery事件
- 附加表单数据对象
- 使用PHP,我如何将JSON blob附加到现有的多级JSON对象
- 枚举附加到文档的HTML对象的所有事件
- Don't将对象中的项附加到html中
- 如何将字符串附加到对象中'路径'在Javascript中
- 如何为给定对象附加标签列表
- JQuery--无法选择动态附加到表中的对象
- 多次克隆对象并在jQuery中附加克隆
- JavaScript:为什么 array.push() 附加两个对象而不是一个对象
- 如何直接附加 Json 对象
- 将新对象“附加”到 ng 重复项
- 如何在Javascript中的对象数组的最后一个对象之后附加几个新对象
- 我注意到我倾向于在JavaScript / jQuery中创建DOM对象并附加它们.这是可以的还是我应该在 HTML 中
- nightwatch页面对象的附加url属性
- 动态访问对象属性(附加字符串)
- 通过在JSON对象中附加属性来获取输入字段值
- 将对象创建附加到鼠标点击
- 节点.js模块 - 将所需对象方法附加到主 App 对象