【问题标题】:File render issue in backbone主干中的文件渲染问题
【发布时间】:2013-03-05 22:34:37
【问题描述】:

我正在尝试使用骨干网和 Django Rest Framework 制作应用程序,并且在渲染模板时遇到了这个问题。我收到以下错误:

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){ 并且似乎没有错误。请提供帮助,因为我对骨干很陌生,并且在每个角落都寻求帮助。

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

【问题讨论】:

    标签: django backbone.js django-rest-framework


    【解决方案1】:

    您正在调用 fetch result 作为函数。

    换行:

    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);
        }
    });
    

    【讨论】:

    • 我的眼睛一定错过了。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多