Marco Kerwitz
Marco Kerwitz

Reputation: 5494

Object attribute not accessible, but there

I've got a data storage object, which basically stores data in its 'attributes' item.

datastorage = {
    attributes: {
        51: {/*data, another object*/}
    }
}

When I log datastorage.attributes to the console I get the expected result. However when I try to access attributes[51] or attributes['51'] or even change the name to attributes['cert_51'] it will always be undefined.

I can't even loop through datastorage.attributes, either it doesn't iterate even once or all I get is the datastorage.attributes object over and over.

$.each(datastorage.attributes, function (name, content) {
    console.log(name, content, this);
    // -> 0, {51:{..}}, {51:{..}
    $.each(this, function () {
         console.log(this);
         // -> {51:{..}}
    });
});

Any hints?

Upvotes: 0

Views: 507

Answers (1)

Marco Kerwitz
Marco Kerwitz

Reputation: 5494

I solved the problem.. I was loading the attributes in question asynchroniously and forgot about that. I implemented a callback that will provide the value of the attribute once it's set.

Upvotes: 1

Related Questions