Enhance .flatten() to support dot-notation

Hi,

I enhanced the .flatten() server connect formatter to support dot-notation, like:

api.data.flatten('users.id')

Here’s the code for the NodeJS target, so the Wappler team can push this update:

flatten: function(arr, prop) {
        if (!Array.isArray(arr)) return arr;
        return arr.map(item => {
            // support nested properties
            if (prop) {
                // clone item to avoid mutating original
                item = Object.assign({}, item);
                let parts = prop.split('.');
                while (parts.length) {
                    item = item[parts.shift()];
                }   
                return item
            }
        });
    },

Needs to be implemented for PHP and other server targets

Community Page
Last updated: