首页 > 解决方案 > django 模板和 Jquery 中未定义的 data-traget 属性

问题描述

我正在尝试访问数据目标值,它正在工作,但随后意外停止,下面是我的 html"

<div class="loan-pending" id='loan-pending-{{loan.loan_id}}' data-target="loan-pending-data-{{loan.id}}" data-query-loan-id="loan={{loan.id}}">
            {% trans 'Loan Applications' %}: {{loan.loan_id}}
          </div>

然后,这是 jquery :

const loanPendingData = $(`#loan-pending-data-${loanID}`);

我也试过了,如下:

const loanPendingData = $(this).data('target');

完整的js脚本:

window.addEventListener("load", function () {
  (function ($) {
    "use strict";

    $(document).ready(function () {
     

      checkQueryParamsForPendingLoans();
     
      function checkQueryParamsForPendingLoans() {
         const loanPendingData = $(`#loan-pending-data-${loanID}`);
       }
     }
})(django.jQuery);

但没有运气,是什么导致 django 和 jquery 出现这种情况?

标签: htmljquerydjangodjango-templates

解决方案


推荐阅读