Search code examples
javascriptarraysbootstrap-table

Bootstrap Table renewal the result


I am using Bootstrap Table

I used this function said in tutorial

function (e, value, row, index)

which is i only use is row and index

now when i retrieve the data using this

console.log(row);

the result is

Object {position: "", username: "test@liferay.com", division: "", status: "1", usertype: ""} 2

Question is how to retrieve all data in different variable or to array

i tried using this way

for (var i in row) {
   console.log(row[i]);
}

the result is

""
"test@liferay.com"
""
"1"
""

Update

I just want to pass all data from row to new variable to retrieve them.

i try to output this way console.log(row[2]); result is undefine


Solution

  • Your variable row is an object, so you need to specify the name to get the value :

    For example, to get the username, you need :

    row.username
    

    If you really need to convert your object into an array, you can use map :

    var obj = {
        position: "",
        username: "test@liferay.com",
        division: "",
        status: "1",
        usertype: ""
    };
    var arr = Object.keys(obj).map(function (key) {return obj[key]});
    console.log(arr[1]);
    

    JSFiddle: http://jsfiddle.net/0985eLg8/