meteor:How do I iterate over an array of objects when property name is not known

dpatnaik

I have an array of objects over which I have to iterate, but I don't know the property name of object.

{{# each }}

{{??}} {{/each}}

Travis White

Break it down into two #eachs. The outer #each loops over the array of objects. The inner #each calls a template helper that returns an array of objects with label and value of each property of that object.

The template:

{{#each arrayOfObjects}}
  {{#each getAllFields}}
     <div class="item">
        {{this.label}} <span class="field-value">{{this.value}}</span>
     </div>
  {{/each}}
{{/each}}

The helper:

getAllFields: function() {
    let fields = [];
    const unknownObject = this;

    _.each(Object.keys(unknownObject), function(theKey) {
        fields.push({label: theKey, value: unknownObject[theKey] });
    });

    fields = _.sortBy(fields, 'label');
    return fields;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I iterate over an array of objects match a common element from another array and return the key value for "name"

How do I iterate over JSON objects?

How to iterate over known property keys in TypeScript?

How to iterate over objects in array and sum a property without iterating?

How to iterate over array of objects and change property in redux?

Iterate over property of array with nested array objects

How to iterate over a list of objects that do not have an id property

How do I Iterate over an array of objects to create new instances of a Class? Ruby on Rails

How can i iterate over array of objects and change group label when its different than last one?

How do I loop over an array of objects to return a property dependent on a corresponding property within that object?

How do you iterate over an array of objects to create a new object?

How can I iterate over an array of objects in JSRender?

How do I iterate over every element of a specific name in a document()?

How do I specify an objects type when Key is a known value?

How i can do a *ngFor in a array of objects that i don't know the name property?

How do I iterate over a JSON array in Golang?

How do I iterate over an array of a custom type in Go?

How do I iterate over an Array field reflectively?

How do I iterate over an array in a nested json object in sqlite?

How do I iterate over properties of an array (not the elements) in javascript?

How do you iterate over this array? I know this is very basic

How do I iterate over an array with a map function, infinitely?

How do I iterate over json result and add to array?

How do I iterate over *args when passing a list?

How to use ngFor to iterate over array of objects

How to iterate over array of objects in Handlebars?

How to iterate over an item of objects and array

How can I iterate over all views known to the data binder?

Iterate over array of objects and change one property in each object