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 的中间,首先需要确定你想要插入按钮的位置。根据你的代码,keyInfo 应该是在处理完 AJAX 请求并解析 JSON 数据后生成的内容。下面是一个简单的方法来将按钮放在 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. // 先处理客户信息和贷款信息
  8. for (const item of jsonRes) {
  9. if (item.code === 'customerInfo') {
  10. // 这里处理客户信息展示
  11. }
  12. if (item.code === 'loan') { // 合同展示
  13. // 处理贷款项逻辑(原有逻辑)
  14. // 在这里插入按钮
  15. const buttonContainer = document.createElement('div');
  16. buttonContainer.innerHTML = `
  17. <div class="button-container">
  18. <button class="btn" data-action="action1">按钮1</button>
  19. <button class="btn" data-action="action2">按钮2</button>
  20. <button class="btn" data-action="action3">按钮3</button>
  21. <button class="btn" data-action="action4">按钮4</button>
  22. </div>
  23. `;
  24. // 在某个特定位置插入 buttonContainer,例如在 item.child 的某个地方
  25. document.body.appendChild(buttonContainer); // 或者指定具体容器
  26. buttonContainer.querySelectorAll('.btn').forEach(button => {
  27. button.addEventListener('click', function() {
  28. const action = this.getAttribute('data-action');
  29. switch (action) {
  30. case 'action1':
  31. console.log('按钮1被点击');
  32. break;
  33. case 'action2':
  34. console.log('按钮2被点击');
  35. break;
  36. case 'action3':
  37. console.log('按钮3被点击');
  38. break;
  39. case 'action4':
  40. console.log('按钮4被点击');
  41. break;
  42. default:
  43. break;
  44. }
  45. });
  46. });
  47. for (const loan of item.child) {
  48. const Index = loan.path.split('.')[1];
  49. let contractCode;
  50. me.overDueInfoIndex[loan.path] = Index;
  51. const child_OverduePeriod = loan.child.find(val => val.code === "overduePeriod");
  52. const child_LoanCharacter = loan.child.find(val => val.code === "loanCharacter");
  53. if (child_LoanCharacter && child_LoanCharacter.value === "Y") {
  54. Object.assign(authMapLoan, { totalPaymentAmount: '' });
  55. }
  56. const child_ProductLine = loan.child.find(val => val.code === "productLine");
  57. if (child_ProductLine && !child_ProductLine.ifVirtual) {
  58. Object.assign(authMapLoan, { installmentLoanAmount: '' });
  59. const productLine = child_ProductLine.line;
  60. const index_isRolloverWhite = loan.child.findIndex(val => val.code === 'isRolloverWhite');
  61. loan.child = loan.child.reduce((arr, child) => {
  62. if (child.code == 'overduePeriod') {
  63. if (child.title.includes("(") && child.title.includes(")")) {
  64. child.title = child.title.replace('(', '(').replace(')', ')');
  65. }
  66. }
  67. if (child.code == 'loanStatus' && child_OverduePeriod && child_OverduePeriod.value == '0') {
  68. child.valueMap[child.value] += `(${lang('NO_DEBT')})`;
  69. }
  70. if (child.code === 'contractCode') {
  71. contractCode = child.value;
  72. me.loanPathContractCodes[loan.path] = child.value;
  73. }
  74. if (child.code === 'allowCollNextPayment' && !child.value) return arr;
  75. const DEFAULT_SHOW = !(child.code in authMapLoan);
  76. const AUTH_SHOW = (child.code in authMapLoan) && canI(authMapLoan[child.code]);
  77. if (DEFAULT_SHOW || AUTH_SHOW) {
  78. arr.push(child);
  79. }
  80. return arr;
  81. }, []);
  82. }
  83. }
  84. }
  85. }
  86. me.keyInfo = jsonRes; // 可以直接使用 jsonRes,而不必再次解析 result。
  87. me.form.initForm(jsonRes);
  88. }
  89. });

修改重点:

  1. 创建并添加按钮信息:在贷款 (loan) 的处理逻辑内,我将创建的 buttonContainer 放在了适当的位置。
  2. 避免重复解析:最后,不再对 result 再次进行 JSON 解析,而是直接使用已解析的 jsonRes.

请根据实际 DOM 结构,将 document.body.appendChild(buttonContainer) 替换为合适的容器,以确保按钮信息出现在预期位置。


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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?