Defyleiti
Defyleiti

Reputation: 555

underscore unexpected token <

Here's my code.

<script type="text/javascript" id="styles_section">
        <select>
            <%_.each(colorOption, function(color){ %>
            <option><%= color.get("color_name") %></option>
            <% }); %>
        </select>
    </script>

I can't seem to find what's wrong with my code.

EDIT:

Here's the json code as requested.

var myColors = [{ color_name: 'white', color_code: '#ffffff'},
                {color_name: 'black', color_code: '#000000'}];

Here's the backbone part.

var colorOption = new Backbone.Collection(myColors);

    var colors = new SelectColorView({
        model: colorOption,
    });

Upvotes: 2

Views: 313

Answers (1)

Fizer Khan
Fizer Khan

Reputation: 92745

Script tag is also used for micro templates. For micro template, script tag type should not be text/javascript.

For micro templates, script tag is as follows

 <script type="text/template"></script>

By setting the type to "text/template", it's not a script that the browser can understand, and so the browser will simply ignore it. This allows you to put anything in there, which can then be extracted later and used by a templating library to generate HTML snippets.

Upvotes: 4

Related Questions