Error: Bad index in range.removeMember: 39


#1

Hi, I’m trying to render some data from collection and I’ve filter by date. ( you pick week and year from calendar ).

However… whenever I switch somehow dates ( I think its 3 times in row ) In console shows this error

Error: Bad index in range.removeMember: 39
    at Blaze._DOMRange.DOMRange.removeMember (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:582)
    at blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2865
    at Object.Tracker.nonreactive (tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:640)
    at Object.removedAt (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2860)
    at Object.removed (observe-sequence.js?hash=5da2e60ce61e074a6463979f3992dd5bac41b43d:296)
    at diff.js:170
    at Array.forEach (<anonymous>)
    at DiffSequence.diffQueryOrderedChanges (diff.js:168)
    at diffArray (observe-sequence.js?hash=5da2e60ce61e074a6463979f3992dd5bac41b43d:218)
    at observe-sequence.js?hash=5da2e60ce61e074a6463979f3992dd5bac41b43d:151

And also some of my code doesn’t work. Data, which shouldn’t be there, are. Thanks for any advice. :slight_smile:

I’ve forgotten to show some of my code:

This is most probably the problematic code, because when i try to evade using him, everything works ‘fine’

formatData = (data) => {
    let payload = [],
        i = 0,
        rendered,
        biggest = 0;

    data.map(accept => {
        if(accept.supplier)
        {
            payload.map(item => {
                if (item.supplier.trim() === accept.supplier.trim()) {
                    item.contracts.push({
                        number: accept.contract,
                        tentative: accept.tentative,
                        tentative_date: accept.tentative_date,
                        color: setColor(accept.tentative_date),
                    });
                    rendered = true;
                    if (item.contracts.length > biggest) biggest = item.contracts.length;
                }
            });

            if(!rendered) {
                payload[i] = {
                    index: i,
                    supplier: accept.supplier.trim(),
                    contracts: [{
                        number: accept.contract,
                        tentative: accept.tentative,
                        tentative_date: accept.tentative_date,
                        color: setColor(accept.tentative_date),
                    }]
                }
            }

            i++;
            rendered = false;
        }
    });

    return payload;
};