0

I have some data that I want to output using jsViews. The case is that objects in data array can have different set of attributes/columns based on some conditions. I store those attributes names in settings and would like to be able to print contents of data with all additional columns stored in a settings array. For example:

data = {
    view_settings: [{
            property_name: "prop1"
        },
        {
            property_name: "prop2"
        }
    ],
    object_list: [{
            id: "180",
            name: "test1",
            prop1: "test-prop-1",
            prop2: "test-prop-2"
        }
    ]
}

What I would like to achieve is to display contents of object_list using property listing from view_settings. Is this even possible using jsViews?

koniczynek
  • 103
  • 1
  • 7

1 Answers1

1

The best way to find an answer for you question is to ask it first, understand it (rubber duck method) and then find an answer.

In order to do this we need to alias objects twice. Here is my simplified jsViews template code which will display correctly data from example from my question:

<script id="template1" type="text/x-jsrender">
    <table>
        <thead>
            <tr>
                <th>Name</th>
                {{for view_settings}}
                <th>{{>property_name}}</th>
                {{/for}}
                <th></th>
            </tr>
        </thead>
        <tbody>
            {{for object_list ~view_settings=#data.view_settings}}
            <tr>
                <th>{{>name}}</th>
                {{for ~view_settings ~object=#data}}
                <th>{{:~object[property_name]}}</th>
                {{/for}}
                <th></th>
            </tr>
            {{/for}}
        </tbody>
    </table>
</script>

Hope this spares someones time ;)

koniczynek
  • 103
  • 1
  • 7