문제

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