在具有标题的单元格中添加溢出表单元格

在具有标题的单元格中添加溢出表单元格

本文介绍了在具有标题的单元格中添加溢出表单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法决定如何使用溢出的单元格访问表并将数据添加到另一个单元格中的这些单元格中.我知道我的解释有点含糊,但请检查图像.

I can't seems to wrap my mind on how should I approach the table with an overflowed cell and add the data in those cell in another cell. I know my explanation is a bit vague but check the images.

最终输出应如下所示:

当前,我正在使用一个名为jquery-csv的jQuery库,并使用了csv.toArrays()方法,该方法为我提供了一个数组作为输出.在我的 JSFiddle 中,我坚持将join()的值添加到正确的位置.因此,在循环中,我正在检查它是否是数组的第4个元素,然后将其后的其余数据连接到单个字符串中,并添加到上一个单元格中.我的问题是如何将添加的连接字符串添加到上一个单元格中?我们将不胜感激.

Currently I'm working on a jQuery library called jquery-csv and using the method csv.toArrays() which gives me an array as output.From my JSFiddle im stuck in adding the value I have join() into the proper place. So in the loop I'm checking if it's the 4th element of the array then the rest of the data after that should be in joined into a single string and added to the previous cell. My problem is how should I add the joined string I have made into it's previous cell? A help would greatly be appreciated.

function generateTable(data) {
var html;
var overflow;
for(var row in data) {
    html += '<tr>\r\n';
    var myStr = [];
    var almost;
    for(var item in data[row]) {
        //html += '<td>' + data[row][item] + '</td>\r\n';
        if(data[row].indexOf(data[row][item]) < 4){
                html += '<td>' + data[row][item] + '</td>\r\n';
        }else{
                myStr.push(data[row][item]);
            console.log(myStr);
            almost = myStr.join(":");
                console.log(almost);
        }

    }
    console.log("this : " + almost); //items all joined
    html += '</tr>\r\n';
}
return html;
}

推荐答案

您可以尝试以下逻辑,在其中可以为最后一列创建单独的文本并将其附加.

You can try below logic where you can create separate text for last column and append it.

var input = $('#here').val();
var data = $.csv.toArrays(input);
function generateTable(data) {
var html;
var overflow;
for(var row in data) {
    html += '<tr>\r\n';
    var myStr = [];
    var almost;
    var lastCol = "<td>";
    var count=0;
    for(var item in data[row]) {
        //html += '<td>' + data[row][item] + '</td>\r\n';
        if(count < 3){
                html += '<td>' + data[row][item] + '</td>\r\n';
        }else{
            if(count>=4) {
              lastCol +=  ":";
            }
            lastCol +=  data[row][item];
        }
       count++;
    }
    lastCol += "</td>";
    console.log("this : " + almost); //items all joined
    html += lastCol + '</tr>\r\n';
}
return html;
}

$("#result").html(generateTable(data));

console.log(data);

JSFiddle演示

JSFiddle Demo

这篇关于在具有标题的单元格中添加溢出表单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:00