Search code examples
ember.jsember-data

How to use an Ember.getOwner(this).lookup('application:main') result


As the title say, I have some problem understanding what does this call return.
This is how I am using it:

fetchEngines()
    {
        let object = Ember.getOwner(this).lookup('application:main').engines;
        console.log(object);
    }

And it return me something like that: example

At this point, this is what I want, the list of all my ember-engines.
But I don't know how to use it. By that I mean, how do I fetch the name of each engine, what is object at this point, I can't find anything about it.

I have tried the forEach() method, but it returns me : object.forEach is not a function. I have also tried the Object.keys method, but it returned me undefined, maybe somebody can indicate me a doc or something, I don't understand at all what is it.
Good day to you and thank you for reading.


Solution

  • I will answer this. This is very simple, and I made a mistake. The Object.keys method work, I didn't know how to write it well.

    This is the corrected version:

    fetchEngines()
        {
            let object = Ember.getOwner(this).lookup('application:main').engines;
            // This will properly show every key in your object
            console.log(Object.keys(object));
            // And if you want to enumerate it
            let filledArray = [];
            for (let key in object) {
                if (object.hasOwnProperty(key))
                    filledArray.push(key);
            }
            // The object filledArray is now a perfectly manipulable object
        }