制表符从表中获取数据但在数组中

时间:2019-05-24 08:36:15

标签: javascript sorting tabulator

我正在使用vuejs从表中获取数据,如下图[“ 1848”],[“ 1796”]等所示,等等。但是数据不在数组中。我需要将数据放入数组以将其传递给php,因为我的查询将是这样

"SELECT * FROM bp.writer WHERE WPNo IN (?)"

console log

这是我的原始代码;

 let tableEntry = this.tableEntry.getRows(); 
    let i = 0;
    for (i = 0; i < tableEntry.length; i++) { 

        var obj = [tableEntry[i]._row.data["WPNo"]];
        //obj["WPNo"] = tableEntry[i]._row.data["WPNo"]; 

        console.log(obj) 
    }  
    //console.log(this.paymenttype) 

      window.open( axios.defaults.baseURL + "/pdf/bookpayment/print.php?Token=" +
                this.$store.getters.objUser.Token +
                "&UserID=" + this.$store.getters.objUser.UserID + 
                "&WPNo=" +  obj +  //need to pass in array
                "&Action=Print",
                "_blank");

我应该使用什么方法或函数将结果转换为数组?

2 个答案:

答案 0 :(得分:1)

尝试一下。

let tableEntry = this.tableEntry.getRows(); 
var array = [];

for (let i = 0; i < tableEntry.length; i++) { 

    var obj = [tableEntry[i]._row.data["WPNo"]];
    //obj["WPNo"] = tableEntry[i]._row.data["WPNo"]; 
    array.push(obj); //saves object into array

    console.log(obj) 
}  
//console.log(this.paymenttype) 

  window.open( axios.defaults.baseURL + "/pdf/bookpayment/print.php?Token=" +
            this.$store.getters.objUser.Token +
            "&UserID=" + this.$store.getters.objUser.UserID + 
            "&WPNo=" +  array +  //pass array
            "&Action=Print",
            "_blank");

答案 1 :(得分:0)

上面的问题质量很低,没有表数据就没了

您问题的答案制表器从表中获取数据但在数组中 http://tabulator.info/docs/4.2/components#component-row

var rowData = row.getData();

const tabledata1 = [{
    id: 1,
    name: "Oli ",
    money: "0",
    col: "red",
    dob: ""
  },
  {
    id: 2,
    name: "Mary ",
    money: "0",
    col: "blue",
    dob: "14/05/1982"
  },
  {
    id: 3,
    name: "Christine ",
    money: "0",
    col: "green",
    dob: "22/05/1982"
  },
  {
    id: 4,
    name: "Brendon ",
    money: "0",
    col: "orange",
    dob: "01/08/1980"
  },
  {
    id: 5,
    name: "Margret ",
    money: "0",
    col: "yellow",
    dob: "31/01/1999"
  },
];


const table = new Tabulator("#example-table", {
  height: 205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
  data: tabledata1, //assign data to table
  layout: "fitColumns", //fit columns to width of table (optional)
  autoColumns: true
});
const removeArrow = function() {
  console.log(table.getData());
}


$('#removeArrow').click(function() {
  removeArrow();
});
<!DOCTYPE html>
<html lang="en">

<script src="https://unpkg.com/tabulator-tables@4.2.4/dist/js/tabulator.min.js"></script>
<link href="https://unpkg.com/tabulator-tables@4.2.4/dist/css/tabulator.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<body>
  <div id="example-table"></div>

  <button id="removeArrow">Get Data in console</button>



</body>

</html>