Get List JS Object Data

Status
Not open for further replies.

startpoint

Active Member
How to get all list data in list_XX.js file?
I tried with
var listdata = Fabrik.getBlock('list_123').options.data
but no luck.
I want to get every row id from list.
 
That's the right place to look.

What event are you firing your code on? It's possible it may be running before the list is initialized. Try this:

Code:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.list.loaded', function(list) {
        var data = list.options.data;
        // data is an array of groups, each group is an object of rows, each row has a data object, each data object has a  __pk_val item which will have the row id
        data.each(function (group) {
            group.each(function (row) {
                // do whatever you need with row.data.__pk_val
                console.log(row.data.__pk_val);
            });
        });
    });
});

-- hugh
 
Note that the main Fabrik.blocks object for the list won't have been added even in that code, so we're using the 'this' (same list object) the list init passes to the fabrik.list.loaded when it fires at the end of the list init. The Fabrik.blocks reference won't be assigned till that function returns, and the next line runs to assign the newly created FbList object to out block structure.

-- hugh
 
Feel free to edit the wiki, when there's stuff you feel should be added. It is a wiki, after all. :)

I added it.

-- hugh
 
I can't read the code in that, my eyes are too old and tired.

You'll need to point me at the page so I can debug it myself.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top