Frage

i've got a little issue with a html template and can't find the mistake. Maybe I'm just missing anything.

Here is my template:

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

            <% for(var i = 0; i < wohnungen.length; i++){ %>        

                        <% var wohnung = wohnungen[i]; 
                        %>

                            <div class="list-item" id="wohnung_"+"<%= wohnung.object_id =%>">

                                <div class="bild-container">
                                    <img src = "<%= wohnung.bild =%>" alt="Red dot" />
                                    </div>

                                <dl class="dl-horizontal">
                                <dt>Anschrift</dt>
                                <dd><%= wohnung.strasse %></dd>
                                <dt>Warmmiete</dt>
                                <dd><%= wohnung.miete %> €</dd>
                                <dt>Kaution</dt>
                                <dd><%= wohnung.kaution %> €</dd>
                                <dt>Flaeche</dt>
                                <dd><%= wohnung.flaeche %> m<sup>2</sup></dd>
                                </dl>

                        <% }; 
            %>  
</script>   

And here the JavaScript how I'm using it:

wohnungen.push({strasse: object.get('Strasse'), miete: object.get('Miete'), kaution: object.get('Kaution'), flaeche: object.get('Flaeche'), bild: bildurl});

                console.log(wohnungen);
                var templateString = document.getElementById('list_tmpl').innerHTML;

                var wohnungsliste = $("#wohnungen");
                wohnungsliste.append(_.template(templateString, {wohnungen: wohnungen}));

I allready made sure, that object isn't empty with the console log, which gives me the following data:

[Object]
0: Object
bild: "http://files.parse.com/33077c6f-9e5d-48ea-9334-5b95bcc0ecf1/1db812ef-de1a-4f91-aba6-a096b68862dc-Jellyfish.jpg"
flaeche: 1
kaution: 1
miete: 1
strasse: "test"
__proto__: Object
length: 1
__proto__: Array[0]

And my Exception:

Uncaught SyntaxError: Unexpected token ) underscore.js:1175
_.template underscore.js:1175
query.find.success Liste.js:94
(anonymous function) parse-1.2.8.js:3683
wrappedResolvedCallback parse-1.2.8.js:3609
(anonymous function) parse-1.2.8.js:3560
_.each._.forEach parse-1.2.8.js:95
_.extend.resolve parse-1.2.8.js:3559
wrappedResolvedCallback parse-1.2.8.js:3618
(anonymous function) parse-1.2.8.js:3560
_.each._.forEach parse-1.2.8.js:95
_.extend.resolve parse-1.2.8.js:3559
wrappedResolvedCallback parse-1.2.8.js:3618
(anonymous function) parse-1.2.8.js:3560
_.each._.forEach parse-1.2.8.js:95
_.extend.resolve parse-1.2.8.js:3559
(anonymous function) parse-1.2.8.js:3613
wrappedResolvedCallback parse-1.2.8.js:3609
_.extend.then parse-1.2.8.js:3643
wrappedResolvedCallback parse-1.2.8.js:3612
(anonymous function) parse-1.2.8.js:3560
_.each._.forEach parse-1.2.8.js:95
_.extend.resolve parse-1.2.8.js:3559
xhr.onreadystatechange

I would really appreciate if someone could go through my code. Maybe there is a mistake I just don't see.

Thanks in forward.

War es hilfreich?

Lösung

Solved:

<div class="list-item" id="wohnung_"+"<%= wohnung.object_id =%>">

                                <div class="bild-container">
                                    <img src = "<%= wohnung.bild =%>" alt="Red dot" />
                                    </div>

The second Equals Sign after wohnung.object_id and wohnung.bild were to much.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top