替代'选项'在backbone.js 1.1.2中

时间:2014-04-23 04:28:45

标签: backbone-views

从我的视图menuitemdetails.js我调用app.js中的选项 - itemDetails

我的menuitemdetails.js

var MenuItemDetails = Backbone.View.extend({
    render: function () {
        var markup = '<div>' +
        '<h1>' + this.options.name + '</h1>' +
        '<p><span class="label">' + this.options.category + '</span></p>' +
        '<img src="photos/' + this.options.imagepath + '" class="img-polaroid" />' +
        '</div>';

        this.$el.html(markup);
        return this;
    }
});

我的app.js

var AppRouter = Backbone.Router.extend({
    routes: {
        "": "list",
        "menu-items/new": "itemForm",
        "menu-items/:item": "itemDetails"
    },

    list: function () {
        $('#app').html('List screen');
    },

    itemDetails: function (item) {
        var view = new MenuItemDetails(
            {
                name: item,
                category: 'Entree',
                imagepath: 'garden-salad.jpg'
            }
        );

        $('#app').html(view.render().el);
    },

    itemForm: function () {
        $('#app').html('New item form');
    }
});

var app = new AppRouter();

$(function () {
    Backbone.history.start();
});

期待替代“选项”,因为从我的观点来看,它不适用于backbone.js 1.1.2

0 个答案:

没有答案