Underscore.js Template Problem - kann Nicht rufen Sie die Methode 'replace' null

Bin ich auf der Suche über und fand eine Menge Antworten, aber keine scheint zu funktionieren.

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>
           Shopping Cart
        </title>
        <link rel="stylesheet" href="lib/style.css" type="text/css">
    </head>
    <body>
<script id="rtemp" type="text/x-underscore-template"">
            <span><%= title %></span>
    </script>
        <script src="lib/jquery.js" type="text/javascript"></script>
        <script src="lib/underscore.js" type="text/javascript"></script>
        <script src="lib/backbone.js" type="text/javascript"></script>
        <script src="lib/script.js" type="text/javascript"></script>
    </body>
    <script>
var Photo = Backbone.Model.extend({


    initialize: function(){
        console.log('this model has been initialized');

        this.bind("change:title", function(){
            var title = this.get("title");
            console.log("My title has been changed to.. " + title);
            var pv = new PhotoView();
            pv.render();
        });

    },

    setTitle: function(newTitle){
        this.set({ title: newTitle });
    },

    setLocation: function(newLoc)
    {
        this.set({location:newLoc});
    }
});

var PhotoView = Backbone.View.extend
({
    el: $('body'),

    render: function(event)
    {
        var name = myPhoto.get('title');
        console.info(name);
        var template = _.template($('#rtemp').html(), {title:name});
        console.info(this.model);
        $(this.el).html(template);
        return this;
    }

});



    </script>
</html>

Ersten;

Erstellen Sie eine neue Instanz der Methode

 var newPhoto = new Photo();
 newPhoto.setTitle('Fishing');

Diese funktionieren, geladen werden, die in den Körper über die Vorlage. Aber wenn ich dann es wieder tun,

newPhoto.setTitle('Sailing');

Bekomme ich den Fehler "Cannot call method "ersetzen " null"

Keine Zeile Fehler, aber ich glaube, es ist an

var template = _.template($('#rtemp').html(), {title:name});

InformationsquelleAutor mcclennon19 | 2012-06-12

Schreibe einen Kommentar