Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将具有数据搜索属性的行移动到另一个表?_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript 如何将具有数据搜索属性的行移动到另一个表?

Javascript 如何将具有数据搜索属性的行移动到另一个表?,javascript,jquery,datatables,Javascript,Jquery,Datatables,我正在尝试将数据表中的选定行移动到另一个数据表。我有这几乎工作,但问题是与单元格上有数据搜索属性。这些数据只是作为[object object]放入我的另一个表中。我试着在文档中找到一个如何处理这个案例的例子,但我没有任何运气。这是我的 HTML <table id="selected_items"> <thead> <tr> <th

我正在尝试将数据表中的选定行移动到另一个数据表。我有这几乎工作,但问题是与单元格上有数据搜索属性。这些数据只是作为
[object object]
放入我的另一个表中。我试着在文档中找到一个如何处理这个案例的例子,但我没有任何运气。这是我的

HTML

<table id="selected_items">
                <thead>
                    <tr>
                        <th>Item</th>
                        <th>Description</th>
                        <th>Crest Allowed</th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>

                <tbody>

                </tbody>
            </table>



<table id="select_items">
                <thead>
                    <tr>
                        <th>Item</th>
                        <th>Description</th>
                        <th>Crest Allowed</th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>

                <tbody>
                    <tr id="1">
                        <td data-search="test">1</td>
                        <td>Testing Bowl</td>
                        <td data-search="nocrest">NO</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                    <tr>
                        <td data-search="test">32</td>
                        <td>Cup Test</td>
                        <td data-search="nocrest">NO</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                    <tr>
                        <td data-search="pristine">3335</td>
                        <td>Bowl Test</td>
                        <td data-search="nocrest">NO</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                    <tr>
                        <td data-search="pristine">120</td>
                        <td>Plate Test</td>
                        <td data-search="yescrest">YES</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                    <tr>
                        <td data-search="test">1000</td>
                        <td>Mug Test</td>
                        <td data-search="yescrest">YES</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                    <tr>
                        <td data-search="pristine">65</td>
                        <td>Ramekin Test</td>
                        <td data-search="yescrest">YES</td>
                        <td><button class="button select">Select</button></td>
                    </tr>
                </tbody>
            </table>

您的基本问题是数据。
当td具有数据属性(数据搜索)时,它包含在数据对象中,因此您的数据数组如下所示: [{display:“1”、@data search:“test”}、“Testing Bowl”、{display:“NO”、@data search:“nocrest”},“Select”]因此数组中的第一个和第三个项实际上是对象,因此[object,object]

因此,最快的(不是我心目中最好的)方法是在添加数据之前修改数据

select_items.on("click", "button.select", function(){
    var selectedRow = select_items.api().row( $(this).parents("tr") ).data();
    console.log(selectedRow);
        selectedRow[0] = selectedRow[0].display;
      selectedRow[2] = selectedRow[2].display;
    selected_items.row.add(selectedRow).draw(true);
});

我还将把数据放在json而不是html中,并使用DataTable和render函数创建按钮。
select_items.on("click", "button.select", function(){
    var selectedRow = select_items.api().row( $(this).parents("tr") ).data();
    console.log(selectedRow);
        selectedRow[0] = selectedRow[0].display;
      selectedRow[2] = selectedRow[2].display;
    selected_items.row.add(selectedRow).draw(true);
});