Backbone.js iterating through object values in tpl

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!

Answers


Yes, it's possible, by adding a code block to do the iteration:

<% for (var key in data) { %>
    <%= data[key] %> 
<% } %>

Need Your Help

Nhibernate dialect and driver to use for connecting to a sybase database in .net

c# nhibernate driver sybase dialect

In version 2 of Nhibernate, I had it working with below fluent nhibernate configuration:

pandas if then statement without looping

python if-statement pandas dataframes

All I'm trying to do is add columns data1 and data2 if in the same row letters is a and subtract if it is c. multipy if it is b. Here is my code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.