【问题标题】:How do I use the explicit variable instead of the column's name如何使用显式变量而不是列名
【发布时间】:2016-12-22 07:06:25
【问题描述】:
  onContentReady: function(e) {

    if (!e.component.detayColumnAdded) {
      e.component.detayColumnAdded = true;
      e.component.addColumn({
        cellTemplate: function(cellElement, args) {
          //$("<a>").text("Detay").on("click", function () {
          $('<a/>').addClass('dx-link')
            .text('Detay')
            .on('dxclick', function(info) {
              var dataGrid = $('#mygrid').dxDataGrid('instance');
              $.each(dataGrid.getSelectedRowsData(), function() {
                var usd = "USD BAKİYE"
                console.log(this.usd); // BUT UNDEFİNED.
              });
            }).appendTo(cellElement)
        }
      });
    }

  },

我正在根据来自 ajax 的数据从列中收集信息。 ajax告诉我如何根据usd余额获取信息。但这并不总是相同的。从 TL 余额栏获取信息。所以我定义了变量 usd。此变量等于列的名称。然后我在控制台中写了 this.usd undefined 。 我该如何解决这个问题。我将如何使它充满活力。能给个建议吗?

【问题讨论】:

    标签: jquery ajax devextreme


    【解决方案1】:

    当您使用变量名来获取对象的键时,请改用[] 表示法:

    console.log(this[usd]); // here
    

    另一种选择是在jQuery.each()的回调函数中传递参数:

    $.each(dataGrid.getSelectedRowsData(), function(i, obj) {
        var usd = "USD BAKİYE"
        console.log(obj[usd]); // BUT bracket notation still required.
    });
    

    【讨论】:

    • @Girl_engineer 不客气,很高兴 [this] 有帮助。
    • 嗨@jai,你能帮我吗?我有一个问题。
    猜你喜欢
    • 1970-01-01
    • 2022-10-17
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多