1

ビューでイベントを発生させようとしていますが、トリガーされていないようです。このビューは別のビュー内から実行されるため、イベントが適切にセットアップされていないかどうかはわかりません。

var ListRow = Backbone.View.extend(
{
    events:
    {
        'click .button.delete': 'destroy'
    },

    initialize: function()
    {
        _.bindAll(this, 'render', 'remove');
    },

    render: function()
    {
        this.el = _.template($('#tpl-sTableList_' + key + 'Row').html());

        return this;
    },


    destroy: function()
    {
        console.log('remove')
    }
});
4

1 に答える 1

3

You're overwriting your this.el, what you want to do instead is

render: function ()
{
    var tpl = _.template($('#tpl-sTableList_' + key + 'Row').html());
    this.$el.empty().html(tpl);
    // or if you prefer the old way
    // $(this.el).empty().html(tpl);
    return this;
},

if that's causing you problems with your DOM representation having an extra wrapped element around it try this instead:

render: function ()
{
    var tpl = _.template($('#tpl-sTableList_' + key + 'Row').html());
    this.setElement(tpl, true); // this is a Backbone helper 
    return this;
},
于 2012-05-16T15:58:39.673 に答える