使用
selector
模板中表格组件的参数,以仅在客户端过滤值。
类似于:
<template name="invoiceList">
<div>
{{> tabular table=TabularTables.Invoices selector=statusSelector class="table table-bordered table-striped table-hover"}}
</div>
</template>
statusSelector
是应返回Mongo样式选择器的模板助手。该选择器可以由会话变量构造。将会话变量设置为下拉选择的值
并在模板助手中获取值。
例如:
Template.invoiceList.events( {
'change #statusdropdown': function(evt) {
var currentTarget = evt.currentTarget;
var statusValue = currentTarget.options[currentTarget.selectedIndex].value;
Session.set('selectedstatus', statusValue);
}
});
Template.invoiceList.helpers({
statusSelector: function () {
var selector = {};
var selectedStatus = Session.get('selectedstatus');
if (selectedStatus)
selector = {status: selectedStatus}; // This is the selector/filter that is going to be applied to the collection.
return selector;
}
});
这里也解释了:
https://github.com/aldeed/meteor-tabular#displaying-only-part-of-a-collections-data-set