代码之家  ›  专栏  ›  技术社区  ›  Aarif Qureshi

在下拉更改事件上绑定aldded表格中的数据

  •  0
  • Aarif Qureshi  · 技术社区  · 8 年前

    我正在使用aldeed表格来显示记录。我已经提交了状态文件。我想根据下拉选择筛选记录。

    有什么办法可以做到这一点吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jos Harink    8 年前

    使用 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