1

I have an object, simulating a Cassandra database, where I retrieve its data to display it on a AngularJs app. Unfortunately, I can't make a premade header for my array because the keys are subject to change, depending on the data I'll retrieve (Here's an example of what I'm talking about):

var columnFamilyData = {
  "DocInfo": {
    "4c58abf5": {
      "name": "coucou",
      "extension": "pdf",
      "size": 8751,
      "type": "facture",
      "repository": "archive"
    },
    "8cd524d7a45de": {
      "name": "gerard",
      "extension": "xml",
      "size": 48734,
      "type": "compta",
    },
    "5486d684fe54a": {
      "name": "splendide",
      "extension": "tiff",
      "type": "photos",
      "METADATA_A": "jambon"
    }
  },
  "Base": {
    "BASE_A": {
      "name": "BASE_A",
      "description": "That base is truly outrageous, they are truly, truly outrageous",
      "baseMetadata_1": "METADATA_A",
      "baseMetadata_2": "METADATA_B",
      "baseMetadata_3": "METADATA_C"
    },
  },
}

As you can see, the arrays in DocInfo and Base are different, data and keys.

What I want to do is being able to use my ng-repeat to create a <th> line with the key name (for instance, Extension, of METADATA_A), but only once, since ng-repeat may duplicate this information.

I'm also providing a JSFiddle, if it can help any of you to understand my goal.

Thanks for reading and/or answering, have a great day.

1 Answer 1

1

Question is not totally clear, but it seems like you want "(key, val) in object" syntax.

ng-repeat="(name, age) in {'adam':10, 'amalie':12}"
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, sorry I wasn't really clear. I tried this already. But I'm getting the object "columnFamilyData" to be transformed in an array using my controller (linked in the pastebin below). So when I'm using ng-repeat on key in my array, it does not return all the keys, and not in the proper order. pastebin.com/DLwH0EzN
Create a working fiddle please. It's too hard without seeing it working.
I hard several js files to include, and not used to jsFiddle. Sorry. To make it short: I want to return the keys in the selected array. For instance, for 4c58abf5 I want to retrieve "name", "extension", "size", "type", "repository' without having to check all my object.
What do you mean 'check all object'? To get keys, for example, via loDash you can <div ng-repeat="(key, row) in columnFamilyData.DocInfo" ng-init="rowKeys = getKeys(row);"><span ng-repeat="rowKey in rowKeys" ng-bind="rowKey"></span></div> and $scope.getKeys = function(obj){ return _.keys(obj); };

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.