Home JS special effects jQuery effects jQuery's JSON dynamically obtains table data code

jQuery's JSON dynamically obtains table data code

jQuery's JSON dynamically obtains table data code

jQuery's JSON dynamically obtains table data code

/*双击展开关闭*/
function dbClick(obj) {
if($(obj).next().is(":hidden")) {
$(obj).next().show();
} else {
$(obj).next().hide();
}
};
$(function() {
$("#mainTable thead").next().empty();
var k = 0;
$.getJSON("revenue.json", function(data) {
$.each(data, function(mainIndex, mainTable) {
/*收入单位*/
var mainTrObj = "<tr class='mainTr warning' ondblclick='dbClick(this)'><td>" + mainTable.incomeUnit + "</td><td>" + mainTable.firm + "</td><td>" + mainTable.number + "</td><td>" + mainTable.instructionType + "</td><td>" + mainTable.dept + "</td><td>" + mainTable.totalPrice + "</td></tr>";
$("#mainTable").append(mainTrObj);
/*支出单位表头*/
var haveChild = data[k].child.length;
if(haveChild == 0) {
var nullHead = "<tr><td colspan='5' align='center'>暂无数据</td></tr>";
$("#mainTable").append(nullHead);
} else {
var smallTit = "<tr><td colspan='6'><table id='smallTable" + k + "' class='table-condensed table smallTable'><tr id='smallTr" + k + "' class='success'><td>支出结算单位</td><td>数量</td><td>支出价格</td><td>费用类型</td></tr></table></td></tr>";
$("#mainTable").append(smallTit);
}
/*支出单位遍历*/
var numnerSum = 0;
var priceSum = 0;
var unsettled = 0;
var child = data[k].child;
for(var j = 0; j < haveChild; j++) {
numnerSum = numnerSum + parseInt(child[j].number);
priceSum = priceSum + parseFloat(child[j].price);
priceSum = Math.round(priceSum * 100) / 100;
unsettled = parseFloat(mainTable.totalPrice) - priceSum;
unsettled = Math.round(unsettled * 100) / 100;
var smallTrObj = "<tr class='smallTr'><td>" + child[j].expendUnit + "</td><td>" + child[j].number + "</td><td>" + child[j].price + "</td><td colspan='2'>" + child[j].type + "</td></tr>";
$("#smallTr" + k).after(smallTrObj);
/*计算数量、价格、未结费*/
}
/*小计行*/
var totalTrObj = "<tr class='danger'><td>小计</td><td>" + numnerSum + "</td><td>" + priceSum + "</td><td align='center'>未结费     " + unsettled + "</td></tr>";
$("#smallTable" + k).append(totalTrObj);
console.log(priceSum);
console.log("未结费" + unsettled);
k++;
});
});

jQuery JSON动态获取表格数据代码是一款jQuery函数调用json表格动态获取数据,表格全部折叠,全部关闭,双击表格行折叠关闭表格。

注:由于服务器不支持JSON,所以会出现无数据,下载压缩包自行搭建!
Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

How to Unmarshall JSON Data Dynamically Based on a Code Value? How to Unmarshall JSON Data Dynamically Based on a Code Value?

31 Oct 2024

Arbitrary Data UnmarshallingIn many scenarios, it's necessary to unmarshall JSON data in a flexible manner, allowing the unmarshalling process to...

CSS3 JQUERY page scrolling effect code_html/css_WEB-ITnose CSS3 JQUERY page scrolling effect code_html/css_WEB-ITnose

24 Jun 2016

CSS3 JQUERY page scrolling effects code

58 jQuery simulated CSS3 transition page switching effects_html/css_WEB-ITnose 58 jQuery simulated CSS3 transition page switching effects_html/css_WEB-ITnose

24 Jun 2016

58 jQuery simulated CSS3 transition page switching effects

jquery waterfall flow LightBox picture box special effects jquery waterfall flow LightBox picture box special effects

06 Jul 2016

jquery waterfall flow LightBox picture box special effects

How to Maintain jQuery Mouseover Effects in ASP.NET UpdatePanels? How to Maintain jQuery Mouseover Effects in ASP.NET UpdatePanels?

03 Dec 2024

jQuery $(document).ready and UpdatePanels: A Refined LookWhen utilizing jQuery to apply mouseover effects to elements within an UpdatePanel, the...

How Can I Dynamically Modify Text on Mouseover using jQuery? How Can I Dynamically Modify Text on Mouseover using jQuery?

13 Nov 2024

jQuery: Dynamically Modifying Text with Mouseover EventsWhen interacting with elements on a web page, adding subtle effects can enhance user...

How to Simulate Hover Effects on Touchscreens Using Long Press? How to Simulate Hover Effects on Touchscreens Using Long Press?

22 Oct 2024

To replicate hover effects on touch-enabled devices, this article proposes a technique using a combination of CSS and JavaScript. It demonstrates how to add hover effects to elements on touchstart and touchend events using jQuery, and how to style th

My Top 5 jQuery Filter & Sort Plugins My Top 5 jQuery Filter & Sort Plugins

21 Feb 2025

Five Top-Notch jQuery Plugins for Filtering and Sorting This article highlights five excellent jQuery plugins for filtering and sorting, each offering unique features and visual effects. These plugins simplify the process of dynamically managing con

CSS3 input box shadow effect and other shadow effects_html/css_WEB-ITnose CSS3 input box shadow effect and other shadow effects_html/css_WEB-ITnose

24 Jun 2016

CSS3 input box shadow effects and other shadow effects

See all articles See all articles

Hot Tools

jQuery2019 Valentine's Day Confession Fireworks Animation Special Effects

jQuery2019 Valentine's Day Confession Fireworks Animation Special Effects

A very popular jQuery Valentine's Day confession fireworks animation special effect on Douyin, suitable for programmers and technical geeks to express their love to the girl they love. No matter you choose to be willing or not, you have to agree in the end.

layui responsive animated login interface template

layui responsive animated login interface template

layui responsive animated login interface template

520 Valentine's Day confession web animation special effects

520 Valentine's Day confession web animation special effects

jQuery Valentine's Day Confession Animation, 520 Confession Background Animation

Cool system login page

Cool system login page

Cool system login page

HTML5 tape music player-CASSETTE PLAYER

HTML5 tape music player-CASSETTE PLAYER

HTML5 tape music player-CASSETTE PLAYER