小编Seb*_*ciu的帖子

Backbone.js - 集合未定义

我正在尝试学习backbone.js,但我仍然坚持抓取json并添加到集合中.集合未定义,我不知道为什么.码:

$(document).ready(function() {
    (function($) {
        //model
        window.Wine = Backbone.Model.extend();

        window.WineCollection = Backbone.Model.extend({
            url: "http://localhost/bootstrap/json.php",
            model: Wine
        });


        //views
        window.WineItemView = Backbone.View.extend({
            template: _.template($("#wine-item-template").html()),
            tagName: 'li',
            render: function() {
                $(this.el).html(this.template(this.model.toJSON()));
                return this;
            }
        });

        window.WineListView = Backbone.View.extend({
            tagName: 'ul',
            initialize: function() {
                this.model.bind('reset', this.render, this);

            },
            render: function() {

                _.each(this.model.models, function(wine) {
                    $(this.el).append(new WineItemView({
                        model: wine
                    }).render().el);
                }, this);
                return this;
            }
        });


        window.WineView = Backbone.View.extend({
            template: _.template($('#wine-template').html()),
            render: function() {
                $(this.el).html(this.template(this.model.toJSON()));
                return this;
            }
        });
        //Router
        window.AppRouter = Backbone.Router.extend({
            routes: …
Run Code Online (Sandbox Code Playgroud)

javascript javascript-framework backbone.js

3
推荐指数
1
解决办法
4351
查看次数