1

I am filling an array with objects with push() function. Then I'm passing as a parameter to customTimer function in the end when I am in the customTimer function i trying to access this array cells but i can't. i tried a few things like refObjArr[0],refObjArr["0"] etc. When I'm trying to console.log("qweqew",typeof refObjArr) it returns object and i tried console.log("Array : ",arr) i can see objects but i can't access anyway

Objects

when Im using jQuery makeArray() function

var arr = $.makeArray(refObjArr)
console.log("custom Timer -> refObjArr : ", refObjArr)
console.log("custom Timer -> type arr: ", typeof arr)
console.log("custom Timer -> arr: ", arr)
console.log("is Array " + jQuery.isArray(arr));

it gives me true but i still can't acess

UPDATE :

for (var i = 0; i < detayBodyArray.length; i++) {
    $.ajax({
        type: "GET",
        url: apiAdress + '/api/Gosterge/defParameters?ekrandetayId=' + detayId[i] + '&bodyIdIndex=' + i,
        dataType: "json",
        success: function (veri) {
            n = detayId.indexOf(veri[2].ekrandetayId);
            setRefObj[n] = {};

            setRefObj[n].yS = parseInt(veri[2].value);
            setRefObj[n].kS = parseInt(veri[2].value);
            setRefObj[n].ekrandetayId = detayId[veri[2].index]
            setRefObj[n].bodyId = bodyId[n];
            setRefObj[n].gostergeTip = tip[n];
            setRefObj[n].gostergeUrl = url[n];
            setRefObj[n].gostergeUrlTip = urlTipi[n];
        },
        error: function (msg) {
            alert(msg.responseText);
        },
        beforeSend: function (xhr, settings) { xhr.setRequestHeader('Authorization', 'Bearer ' + token); }
    });
    if (i === detayBodyArray.length - 1) {
        customTimer();
    }
}

detayBodyArray coming from another func., refObjArr is a global array

7

1 Answer 1

1

I solve this problem with another way. I created simple class like this

class refIndicator {

        constructor(ekrandetayId, bodyId, gostergeTip, gostergeUrl, gostergeUrlTip, yS, kS) {
            this.ekrandetayId = ekrandetayId
            this.bodyId = bodyId
            this.gostergeTip = gostergeTip
            this.gostergeUrl = gostergeUrl
            this.gostergeUrlTip = gostergeUrlTip
            this.yS = yS
            this.kS = kS
        }
    }

then fill in created and fill reference in ajax request then push into global array and it works .

     for (var i = 0; i < detayBodyArray.length; i++) {
                 $.ajax({
                     type: "GET",
                     url: apiAdress + '/api/blabla/bla/ekrandetayId=' + detayId[i],
                     dataType: "json",
                     success: function (veri) {
                         n = detayId.indexOf(veri[2].ekrandetayId);
                         setRefObj = new refIndicator(detayId[veri[2].index], bodyId[n], tip[n], url[n], urlTipi[n], parseInt(veri[2].value), parseInt(veri[2].value));
refObjArr.push(setRefObj)
                         if (refObjArr.length === detayBodyArray.length - 1) {
                             customTimer()
                         }
                     },
                     error: function (msg) {
                         alert(msg.responseText);
                     },
                     beforeSend: function (xhr, settings) { xhr.setRequestHeader('Authorization', 'Bearer ' + token); }
                 });

             }



  function customTimer() {
        console.log("custom Timer -> refObjArr : ", refObjArr[2])
        console.log("custom Timer -> refObjArr kS : ", refObjArr[2].kS)
        console.log("custom Timer -> refObjArr edId : ", refObjArr[2].ekrandetayId)
        console.log("custom Timer -> refObjArr bId : ", refObjArr[2].bodyId)
        console.log("custom Timer -> refObjArr gTip : ", refObjArr[2].gostergeTip)}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.