我使用Reactive-Table來顯示保存在我的Meteor應用程序中的數據,如下面的代碼所示,表中的每一行都有一個鏈接來編輯與此行相關的文檔。我正在嘗試使用編輯鏈接'點擊事件'來捕獲與所選行相關的文檔的_id,但似乎無法得到_id,有人可以檢查我的代碼並讓我知道我在想什麼這裏錯了,如何捕捉_id?由於流星從反應表中檢索文件_id
customerslist.html
<template name="customerslist">
<div class="customerslist">
<div class="page-header">
<h1>Customers List</h1>
</div>
<div>
{{> reactiveTable class="table table-bordered table-hover" collection=customersCollection settings=settings}}
</div>
</div>
</template>
customerslist.js
Template.customerslist.helpers({
customersCollection: function() {
return Customers.find({},{sort: {title: 1}});
},
settings: function() {
return {
rowsPerPage: 10,
showFilter: true,
showColumnToggles: false,
fields: [
{ key: 'name', label: 'Customer Name' },
{ key: 'email', label: 'Email' },
{ key: 'phone', label: 'Phone' },
{ key: '_id', label: 'Action', sortByValue: false, fn: function(_id){ return new Spacebars.SafeString('<a name="' + _id +'" class="edtlnk" target="_blank" href="' + _id + '/edit"> Edit </a>'); } }
]
};
}
});
Template.customerslist.customers = function() {
return Customers.find({},{sort: {title: 1}});
};
Template.customerslist.events({
'click .edtlnk': function(e) {
var cust = this;
event.preventDefault();
console.log('Customer ID: '+cust._id);
}
});