2013-03-17 52 views
1

我正在尝试使用主干和Django Rest框架来制作应用程序,并且我正在使用呈现模板来处理此问题。我得到以下错误:主干中的文件呈现问题

Uncaught TypeError: object is not a function

骨干

var EditBook = Backbone.View.extend({ 
el:'.page', 
render: function (options) { 
    var that = this; 
    if(options.id) { 
     var book = new Book({id: options.id}); 
     book.fetch()({ 
      success: function(book) { 

       var template = _.template($('#edit-book-template').html(), {book: null}); 
       that.$el.html(template); 
      } 
     }) 
    } else { 
     var template = _.template($('#edit-book-template').html(), {book: null}); 
     this.$el.html(template); 
    } 
} 
}); 

我试图检查程序的控制流,它看起来像在行中的出错点:success: function(book){,有似乎并不是一个错误。请帮助,因为我对骨干很陌生,并且在每个角落寻求帮助。

编辑:该问题已解决,因此删除了不相关的代码。

回答

1

您正在调用提取结果作为函数。

更改行:

book.fetch()({ 
    success: function(book) { 
     var template = _.template($('#edit-book-template').html(), {book: null}); 
     that.$el.html(template); 
    } 
}) 

到:

book.fetch({ 
    success: function(book) { 
     var template = _.template($('#edit-book-template').html(), {book: null}); 
     that.$el.html(template); 
    } 
}); 
+0

我的眼睛一定是错过了。非常感谢。 – 2013-03-17 16:21:53