クリックしたアイテムの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}テンプレートからクリックされたアイテムを取得する方法は?