如何知道我点击的项目的 ID?我的代码如下:
$(function() {
ipl.mvc.view.openings_view = ipl.mvc.view.view_base.extend({
template: '/assets/t/plmt/companies.tmpl.html',
ID: '#tmpl_openings',
events: {
"click #edit": "editpost"
},
initialize: function() {
var _this = this;
_.bindAll(this, 'addOne', 'addAll', 'render', 'editpost');
_this.loadTemplate(_this.template, function() {
_this.model = new ipl.mvc.model.companies_model([]);
_this.model.view = _this;
_this.model.bind('change', _this.render, _this);
});
}
,
render: function() {
var _this = this
jsonData = _this.model.toJSON();
_.each(jsonData, function(model) {
$(_this.ID).tmpl(model).appendTo(_this.el);
return _this;
});
}
,
editpost: function(e) {
console.log("EDIT CLICKED");
e.preventDefault();
var ele = $(e.target);
console.log(ele);
_this.model = new ipl.mvc.collection.companies_collection([]);
var id = _this.model.get("id");
alert(id);
}
});
});
和模板
<a href="!/editpost/${id}" data-id="${id}"><button id="edit" ><img src="/assets/img/pencil.png" /></button></a>
我需要 id 才能在编辑功能中使用,但不是${id}
从模板中获取,我按照这些步骤操作但我没有得到它?如何${id}
从模板中获取点击的项目?