ZBLOG

$.ajax({ method: "POST", url: "../d/detail/keyInfo", data: { custId: custId }, success: function(result) { var jsonRes = JSON.parse(result); for (const item of jsonRes) { if (item.code === 'customerInfo...

如果你希望在 keyInfo 的中间添加按钮,可以在获取并处理数据时,将按钮的 HTML 代码插入到 keyInfo 中。可以通过将创建的 buttonContainer 添加到适当的位置来实现。假设你希望在处理 keyInfo 数据后,直接插入到该数据结构中,这里是一个示例如何进行操作。

下面是更新后的代码片段:

  1. $.ajax({
  2. method: "POST",
  3. url: "../d/detail/keyInfo",
  4. data: { custId: custId },
  5. success: function(result) {
  6. var jsonRes = JSON.parse(result);
  7. for (const item of jsonRes) {
  8. if (item.code === 'customerInfo') {
  9. // 客户信息展示
  10. }
  11. if (item.code === 'loan') { // 合同展示
  12. // 创建按钮容器
  13. const buttonContainer = document.createElement('div');
  14. buttonContainer.innerHTML = `
  15. <div class="button-container">
  16. <button class="btn" data-action="action1">按钮1</button>
  17. <button class="btn" data-action="action2">按钮2</button>
  18. <button class="btn" data-action="action3">按钮3</button>
  19. <button class="btn" data-action="action4">按钮4</button>
  20. </div>
  21. `;
  22. // 在合适的位置插入按钮容器
  23. const keyInfoSection = document.querySelector('#key-info-section'); // 假设这是你的 keyInfo 展示区域的选择器
  24. keyInfoSection.appendChild(buttonContainer);
  25. buttonContainer.querySelectorAll('.btn').forEach(button => {
  26. button.addEventListener('click', function() {
  27. const action = this.getAttribute('data-action');
  28. switch (action) {
  29. case 'action1':
  30. console.log('按钮1被点击');
  31. // 执行按钮1的操作
  32. break;
  33. case 'action2':
  34. console.log('按钮2被点击');
  35. // 执行按钮2的操作
  36. break;
  37. case 'action3':
  38. console.log('按钮3被点击');
  39. // 执行按钮3的操作
  40. break;
  41. case 'action4':
  42. console.log('按钮4被点击');
  43. // 执行按钮4的操作
  44. break;
  45. default:
  46. break;
  47. }
  48. });
  49. });
  50. for (const loan of item.child) {
  51. const Index = loan.path.split('.')[1];
  52. let contractCode;
  53. me.overDueInfoIndex[loan.path] = Index;
  54. const child_OverduePeriod = loan.child.find(val => val.code === "overduePeriod");
  55. const child_LoanCharacter = loan.child.find(val => val.code === "loanCharacter");
  56. if (child_LoanCharacter && child_LoanCharacter.value === "Y") {
  57. Object.assign(authMapLoan, { totalPaymentAmount: '' });
  58. }
  59. const child_ProductLine = loan.child.find(val => val.code === "productLine");
  60. if (child_ProductLine && !child_ProductLine.ifVirtual) {
  61. Object.assign(authMapLoan, { installmentLoanAmount: '' });
  62. loan.child.reduce((arr, child) => {
  63. if (child.code == 'overduePeriod' && child.title.includes("(") && child.title.includes(")")) {
  64. child.title = child.title.replace('(', '(').replace(')', ')');
  65. }
  66. if (child.code == 'loanStatus' && child_OverduePeriod && child_OverduePeriod.value == '0') {
  67. child.valueMap[child.value] += `(${lang('NO_DEBT')})`;
  68. }
  69. if (child.code === 'contractCode') {
  70. contractCode = child.value;
  71. me.loanPathContractCodes[loan.path] = contractCode; // 使用变量而不是重复调用值
  72. }
  73. if (child.code === 'allowCollNextPayment' && !child.value) return arr;
  74. const DEFAULT_SHOW = !(child.code in authMapLoan);
  75. const AUTH_SHOW = (child.code in authMapLoan) && canI(authMapLoan[child.code]);
  76. if (DEFAULT_SHOW || AUTH_SHOW) {
  77. arr.push(child);
  78. }
  79. return arr;
  80. }, []);
  81. }
  82. }
  83. }
  84. }
  85. me.keyInfo = jsonRes; // 不需要再 parse,因为已经是对象了。
  86. me.form.initForm(jsonRes);
  87. }
  88. });

注意事项:

  • 确保 #key-info-section 是实际存在于 DOM 中的元素 ID 或选择器。
  • 根据需要调整样式,以确保新插入的内容与页面整体风格一致。
  • 记得根据业务逻辑和需求调整其他功能。


    内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://sdn.0voice.com/?id=7628

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?