I really have problems with name conflicts in my Mustache templates (using Mustache.js). This example illustrates these two problems:
I pass this data:
{'recs': {'code': 'foo', 'id': 1 'childRecs': [{'id': 2}, {'code': 'bar', 'id': 3}] } }
In this template:
{{
Expected:
Record ID: 1 This child code is: [] and its parent ID is 1 This child code is: [bar] and its parent ID is 1
Actual:
Record ID: 1 This child code is [foo] and its parent ID is 2 This child code is [bar] and its parent ID is 3
In the nested block {{#childRecs}}
there is no access to the parent field {{#recs}}{id}}{{/recs}}
- it is overwritten {{#childRecs}}{{id}}{{/childRecs}}
If there is no variable in {{#childRecs}}
and a parent variable with the same name exists, there is no way to prevent the parent variable from printing.
My nested structures are very deep and there are many name conflicts, so renaming them in such a way that they do not collide is not a viable option. Is there any other way to solve my problems?
source share