我在backgridjs表自定义" TagCell" (已实施THIS)。
所以我的细胞看起来像:
var TagCell = Backgrid.TagCell = Cell.extend({
className: "tag-cell",
events: {
'click .tag a': 'removetag',
},
initialize: function (options) {
TagCell.__super__.initialize.apply(this, arguments);
this.title = options.title || this.title;
this.target = options.target || this.target;
var model = this.model;
var rawData = this.formatter.fromRaw(model.get(this.column.get("name")), model);
},
removetag: function(event) {
var that = this;
that.model.set({location: ""},{success: alert("removed!"));
},
render: function () {
this.$el.empty();
var rawValue = this.model.get(this.column.get("name"));
var formattedValue = this.formatter.fromRaw(rawValue, this.model);
this.$el.append('<input name="location" class="tagggs" value="'+formattedValue+'" />');
this.delegateEvents();
return this;
},
});
如果我尝试通过事件调用 removetag 功能,请点击&#34; .tag&#34;保存具有空位置的模型。但是,如果我尝试将点击事件调用到&#34; .tag a&#34;或直接上课&#34; .rmvtag&#34;函数未被调用。我认为因为jquery标签输入的设计如下:
$('<span>').addClass('tag').append(
$('<span>').text(value).append(' '),
$('<a>', {
href : '#',
class : 'rmvtag',
text : 'x'
}).click(function () {
return $('#' + id).removeTag(escape(value));
})
).insertBefore('#' + id + '_addTag');
因此在追加元素后直接写入了removetag()的click函数。如何通过点击rmvtag链接从主干调用保存模型功能? 谢谢你的帮助!