简体   繁体   English

我试图传递 HTML 代码和一些变量时不需要的逗号

[英]Unwanted commas while I am trying to pass HTML code and some variables

I am working on a Photoshop CEP extension and I am using jquery-confirm for my alerts.我正在开发Photoshop CEP扩展,并且我正在使用jquery-confirm作为我的警报。 My problem is that I get some unwanted commas while I am trying to pass an HTML table and some variables to a jquery-confirm alert !!!我的问题是,当我尝试将HTML 表和一些变量传递给jquery-confirm 警报时,我得到了一些不需要的逗号 Here is the code which is responsible for this part...这是负责这部分的代码......

function list_FoundLayers() {
  try {
    // Checks if should get layers data by layer name and HEX color or not.
    let layersData;
    if (htmlElements.content.specificNameTxtbox.value === "") {
      layersData = filter_layersData(false)
    } else {
      layersData = filter_layersData(true)
    };

    // Creates a table row for each layer.
    let tableRows = [];
    for (let i in layersData) {
      let hasEffect;
      if (layersData[i][3] === 'true') {
        hasEffect = '<i class="fas fa-check"></i>'
      } else {
        hasEffect = '<i class="fas fa-times"></i>'
      };
      let isVisible;
      if (layersData[i][4] === 'true') {
        isVisible = '<i class="fas fa-check"></i>'
      } else {
        isVisible = '<i class="fas fa-times"></i>'
      };
      let tableRow = `<tr id="jc-table-layer-data-${i}" layerID="${layersData[i][1]}" class="inner-row">
                                <td>${layersData[i][1]}</td>
                                <td>${layersData[i][5]}</td>
                                <td>${layersData[i][0]}</td>
                                <td>${hasEffect}</td>
                                <td>${isVisible}</td>
                            </tr>`;
      tableRows.push(tableRow);
    };

    // Creates the whole HTML table.
    let htmlCode = `<table class="jc-table" id="jc-table"><thead><tr><th>ID</th><th>Type</th><th>Name</th><th>FX</th><th>Visible</th></tr><tfoot><tr><td colspan="5">Found <b>${tableRows.length}</b> layers in total.</td></tr></tfoot><tbody>${tableRows}</tbody></table>`

    // Gives result using a jquery-confirm.
    commonAlert(
      'blue',
      null,
      'Found Layers',
      htmlCode,
      function() {
        manipulateHTMLElements('disable')
      },
      function() {
        for (let i in layersData) {
          const $thisElement = $(`#jc-table-layer-data-${i}`);
          const $thisElementBackgroundColor = $($thisElement).css('backgroundColor');

          // Select specific layer when user click on it.
          $($thisElement).click(
            function() {
              $(this).css('background', 'rgba(0,0,0,0.5)');
              selectById($(this).attr("layerID"))
            }
          )
          // When user click anywhere else.
          $(document).mouseup(
            function(element) {
              if (!$thisElement.is(element.target) && $thisElement.has(element.target).length === 0) {
                $($thisElement).css('background', $thisElementBackgroundColor)
              }
            }
          )
        };
      },
      function() {
        this.close()
      },
      function() {
        manipulateHTMLElements('enable')
      }
    );
  } catch (err) {
    catchJSErrorAlert(getStack(err.stack, 'fullStuck'), getStack(err.stack, 'fnName'), getStack(err.stack, 'fileName'), getStack(err.stack, 'lnNum'), getStack(err.stack, 'colNum'), err.name, err.message);
  };
};

And here is an image of the issue. 是问题的图像。

As noticed by Zydna, you need to make a string out of your tableRows...正如 Zydna 所注意到的,您需要从 tableRows 中制作一个字符串...

<tbody>${tableRows.join('\n')}</tbody> //\n not necessary but help to debug...

also I think you forgot to close the <thead> tag in your html line.我还认为您忘记关闭 html 行中的<thead>标记。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试将一些 PHP 变量和 Javascript 变量传递到 Javascript window.location.href 中的 url - I am trying to pass some PHP variables and Javascript variable into url in Javascript window.location.href 我试图将一些表单数据从一个html页面传递到另一个页面 - I am trying to pass some form data from one html page to another 我试图将CORS正确地实现到我的JavaScript代码,并且工作了一段时间,我相信项目中缺少一些文件吗? - I am trying to implement CORS to my JavaScript code correctly, and it worked for a while, I believe I am missing some file from the project? 我正在尝试在 javascript [codeigniter post 方法] 中传递 3 个变量 - i am trying to pass 3 variables in javascript [codeigniter post method] 我在尝试将数组传递给类时变得不确定 - I am getting undefined while trying to pass array to a class 我正在尝试简化此代码 - I am trying to simplify this code 我试图通过复选框获取多选下拉列表,在填充项目并获取allChecked工作时遇到一些问题 - I am trying to get a multiselect dropdown with checkbox, facing some issue while populating items and getting allChecked work 试图用 html 学习 php,但我在提交带有由某些 javascript 提供的变量的表单时遇到问题? - Trying to learn php with html but I am having trouble submitting a form with a variable that is given by some javascript? 我试图在 object 中传递 function,但每次运行代码时,它都会返回“[Function:property]” - I am trying to pass a function in an object, but every time I run the code, it returns "[Function:property]" 我试图将视频添加到我的konami代码中,但遇到了一些麻烦 - I am trying to add a video to my konami code and running into some trouble
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM