2012-12-19 14 views
6

मैं backbone.js सीख रहा हूं और मैं शुरुआत में काफी कुछ हूं। मैं underscore टेम्पलेट विधि के माध्यम से एक टेम्पलेट जोड़ना चाहता हूं लेकिन यह मेरे लिए काम नहीं कर रहा है। मैंने इस त्रुटि की खोज की लेकिन इसे स्वयं ठीक नहीं कर सका। यदि यह टेम्पलेट नहीं दिखा रहा है तो मैं आगे कैसे बढ़ सकता हूं। कुछ मदद दोस्तों की जरूरत है।टेम्पलेट backbone.js में लोड नहीं हो रहा है (TypeError: टेक्स्ट अपरिभाषित है)

<!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

मुझे समस्या मिली। टेम्पलेट धारण करने वाला स्क्रिप्ट टैग जेएस कोड से पहले रखा जाना चाहिए अन्यथा यह कंसोल में दिखाना जारी रखेगा (टाइपर-टेक्स्ट अनिर्धारित है)। :) – Michael

+0

आप अपनी सभी जावास्क्रिप्ट और टेम्पलेट '

4

मुझे एक ही त्रुटि मिली। सुनिश्चित करें कि परिभाषित आईडी पृष्ठ पर मौजूद टेम्पलेट मौजूद है। मेरे मामले में मैंने टेम्पलेट के लिए गलत आईडी का उपयोग किया था, और यह त्रुटि त्रुटि का कारण था "TypeError: n अपरिभाषित है"

संबंधित मुद्दे