質問

I have an Object containing Arrays containing Objects
Example:

main: {
  arr1: [
    obj1: {x: 0, y: 0},
    obj2: {x: 0, y: 0}
  ],
  arr2: [
    obj3: {x: 0, y: 0},
    obj4: {x: 0, y: 0}
  ]
}

I need with Mustach to retrieve all the x values of those objects (obj1 - 4).
Every object and array can have a random name.

I tried:

{{#main}}
  {{#.}}
    {{x}}
  {{/.}}
{{/main}}

But it's not working.
Anyone have an idea?

Thanks

役に立ちましたか?

解決

If I'm not mistaken, when a section refers to an object, the properties of the object are exposed inside the section, but there is not iteration. So in the section {{#main}}, arr1 and arr2 are exposed, and {{#arr1}} would iterate the array.

他のヒント

None of those things in your example are arrays, they're all objects. Arrays have 0-indexed consecutive numeric keys. That's all you can iterate over in Mustache.

If you want to iterate over the values of objects, you should prepare your data before passing it off to Mustache. Something like Underscore.js's _.values function is super useful for that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top