2012-12-19 17 views
6

backbone.js öğreniyorum ve başlangıçta oldukça fazla. Şablonu underscore şablon yöntemiyle eklemek istiyorum, ancak benim için çalışmıyor. Bu hatayı aradım ama düzeltemedim. Şablonu göstermiyorsa nasıl ileri gidebilirim? Biraz yardıma ihtiyacım var.template backbone.js'de yüklenmiyor (TypeError: text undefined)

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>testing</title> 
</head> 
<body> 
<script src="scripts/jquery.js"></script> 
<script src="scripts/underscore.js"></script> 
<script src="scripts/backbone.js"></script> 
<script> 


    var TodoView = Backbone.View.extend({ 
    tagName: 'li', 
    // Cache the template function for a single item. 
    todoTpl: _.template($('#item-template').html()), 

    events: { 
    'dblclick label': 'edit', 
    'keypress .edit': 'updateOnEnter', 
    'blur .edit': 'close' 
    }, 

    // Re-render the titles of the todo item. 

    render: function() { 
    this.$el.html(this.todoTpl(this.model.toJSON())); 
    this.input = this.$('.edit'); 
    return this; 
    }, 

    edit: function() { 
    // executed when todo label is double clicked 
    }, 

    close: function() { 
    // executed when todo loses focus 
    }, 

    updateOnEnter: function(e) { 
    // executed on each keypress when in todo edit mode, 
    // but we'll wait for enter to get in action 
    } 

    }); 


    var todoView = new TodoView(); 
    // logs reference to a DOM element that cooresponds to the view instance 
    console.log(todoView.el); 
+3

sorunu buldum. Şablonu tutan komut dosyası etiketi js kodundan önce yerleştirilmeli, aksi halde konsola gösterilmeye devam edecektir (Typeerror-text is undefined). :) – Michael

+0

Tüm 'JavaScript' ve '

4

Aynı hatayı aldım. Sayfada tanımlı kimlik numarası bulunan şablonun bulunduğundan emin olun. Benim durumumda, şablon için kimlik numarası kullanıyorum ve bu hata nedeni "TypeError: n undefined".

İlgili konular