I’m using backbone.js and am curious if it’s possible to iterate through a generic object key/values in the tpl. Example:
Model data received from the server:
{
id: "someid",
data: {
key1: "some value",
key2: "some value"
}
}
The tpl I’m using looks something like this:
<script type="text/template" id="tpl-object-list-item">
<%%= id %> - <%%= data %>
</script>
which outputs something like this:
someid - [object Object]
I know it’s possible to use something like <%%= data.key1 %> but I’m wondering if it’s possible to iterate through the key/value pairs in data without explicitly calling them out.
Any help would be much appreciated!
Yes, it’s possible, by adding a code block to do the iteration: