jquery - 在表格ajax上显示json
问题描述
如何使用 ajax 显示以下代码问题是,我无法显示 chequebook.statuses.name 我只需要打印名称所有数据都可以,但名称
ajax调用如下
success: function(data) {
$("#edit-error-bag").hide();
$.each(data, function(i, chequeBook){
var test = null;
$.each(chequeBook.statuses , function(k , v ){
test = v[1]
})
$("#tbody").html("<tr><td>" + chequeBook.id + "</td><td>" +
chequeBook.account_id + "</td><td>" + chequeBook.number_of_books
+ "</td><td>" + chequeBook.number_of_leaves + "</td><td>" +
((chequeBook.currency_id == 1 ) ? 'USD' : 'USD') + "</td><td>" +/*
((chequeBook.statuses != 'undefined') ? 'Fine' : 'Not Fine' )*/
json数据的内容
{"error":false,"chequeBookRequest":{
"id":50,10:42:56","account_id":46764995,
"modifier_id":null,
"statuses":{"id":4,"name":"Collected","description":"Cheque book is collected by a customer","created_at":"2020-02-18 10:27:05","updated_at":"2020-02-18 10:27:05","deleted_at":null},
"modifiers":null}
}
上面的代码不起作用我尝试了一切似乎都没有工作从到到ChequeBook.statuses.name
没有chequeBook[statuses][name]
工作我只是尝试显示状态的名称而不是整个对象。chequeBook.statuses[0].name
chequeBook.statuses['name']
解决方案
您的响应状态不是数组。它们是一个对象。
您当前的尝试表明您正在尝试像访问数组一样访问它。
假设chequeBook
是一个chequeBookRequest
在您的 JSON 响应中引用的变量,那么您可以使用chequeBook.statuses.name
.
推荐阅读
- powerbi - 在 DAX PowerBI 中连接
- mysql - MySQL 复合索引列顺序和性能
- django - django DetailView 如何显示详细信息页面
- java - 在 ConditionalOnProperty 注释中使用主机名
- logstash - 使用 dissect 进行日志解析
- javascript - ts-node 在 OS X 上运行测试,但不在 Ubuntu 上
- xamarin.forms - 以 xamarin 形式接收来自 android 光束的消息
- c# - 每次要使用类中的函数时调用“新”
- sql-server-2012 - 如何在 SQL Server 2012 中使用 OPENROWSET 在文件名中插入基于当前日期的数据?
- docker - 多阶段构建映像不起作用,而正常构建则起作用