How do I get data from a model type?

I am a complete noob with Ember and I need to get data from an external site written in Ember.

I installed the Ember inspector plugin and I see the following:

enter image description here

What javascript command can I enter in the debug console window to get the data (Id and Number) in the list?

I cannot rely on Ember's inspector to find data, this tool is only used to inspect the structure.


Update 1

Thanks to @kumkanillam, I did it here:

enter image description here

It seems that I can find out the name and type of each attribute of the element in my list, but I cannot get its value.

The array happy

is the result of this call from his example:myStore.peekAll('common/following-info').toArray()

+3


source to share


1 answer


Take a look at this
https://guides.emberjs.com/v2.14.0/ember-inspector/container/ https://guides.emberjs.com/v2.14.0/ember-inspector/object-inspector/#toc_exposing-objects- to-the-console

This reflected the images very well.

You can open objects in the console by clicking a button $E

inside the inspector. This sets the global variable $ E to the selected object.

You can also open console properties. When you hover an object over the objects, a button appears next to each property $E

. Click on it to display the property value to the console.


Update 1

You can run the below code in the console.

 function getApplication() {
  let namespaces = Ember.Namespace.NAMESPACES;
  let application;

  namespaces.forEach(namespace => {        
    if (namespace instanceof window.Ember.Application) {
      application = namespace;
      return false;
    }
  });
  return application;
}

      

you can use the above function to get the application instance, from there you can search for access service:store

, from there you can use the peekAll

model you want . to view all the required data, I used JSON methods like stringify and then parsing.

I actually used the LinkedIn site and used my model common/following-info

for the demo. you can choose any model you want to view,



var myApp = getApplication();
var myStore = myApp.__container__.lookup('service:store')
myStore.peekAll('common/following-info')
myStore.peekAll('common/following-info').toArray()
JSON.stringify(myStore.peekAll('common/following-info').toArray())
JSON.parse(JSON.stringify(myStore.peekAll('common/following-info').toArray()))

      


Update 2

myStore.peekAll('common/following-info')

Here it returns DS.RecordArray and extends Ember.ArrayProxy , which means you can use the methods available in ArrayProxy. forEach to iterate or to get a specific index entry use objectAt (index)

In your case, you need to know the name of the model property in order to get the values ​​for a specific property, for example

let allRecords = myStore.peekAll('common/following-info');
allRecords.forEach(function(item){
  console.log(item);
  console.log(' Using get method to value ', item.get('propName'));
});

      

to get a specific index value,

let allRecords = myStore.peekAll('common/following-info');
let firstRecord = allRecords.objectAt(0);
console.log(' First record propName value is',firstRecord.get('propName'));

      

In your case, you want to print the entire object without specifying the names of each property, then there is no built-in way. We need to do some hacks with JSON.stringify

and parse

to get the perfect object you are looking for and then you can use Object.values

to get all the values.

let arrayOfObjectWithOnlyKeysAndValuesOfModel = JSON.parse(JSON.stringify(myStore.peekAll('common/following-info').toArray()));
arrayOfObjectWithOnlyKeysAndValuesOfModel.forEach(function(item){ 
 console.log('item',item);
 console.log(' item values alone ', Object.values(item));
});

      

+2


source







All Articles