Grasper
Grasper

Reputation: 1313

How to push an object inside the nested object?

I get longDesc from a second AJAX call and I'd like to merge it with the first call.

My code:

transform: {
    fn(data) {
        const longDesc = [];
        Ext.Ajax.request({
        url: `url`,
        method: 'GET',
        scope: this,
        success(response) {
            const dataSet = Ext.decode(response.responseText);
            Ext.each(dataSet.data, value => {
            longDesc.push(value.longDesc);
            });
        },
        failure() {},
        });
        data.data.longDesc = longDesc;              
        return data;
},          

I get this log:

enter image description here

but I'd like to move longDesc inside each data object

enter image description here

Upvotes: 0

Views: 32

Answers (1)

Aditya Kumbhar
Aditya Kumbhar

Reputation: 96

You need to set the longDesc array in each element in data and not attach it directly to data.I think this is what you are trying to achieve-

transform: {
    fn(data) {
        const longDesc = [];
        Ext.Ajax.request({
        url: `url`,
        method: 'GET',
        scope: this,
        success(response) {
            const dataSet = Ext.decode(response.responseText);
            Ext.each(dataSet.data, value => {
            longDesc.push(value.longDesc);
            });
        },
        failure() {},
        });
        data.data.forEach(function(entry) {
         entrylongDesc = longDesc;
        });
        return data;
}, 

Upvotes: 1

Related Questions