Blaze. Allow users filtration data contained in the data collection


#1

Hello application must allow users filtration data contained in the data collection. The filter has to be supported by the checkboxes. The user selects (checkbox) it interesting data (name, address …) and submit your selection. The table below displays the selected data from the data collection.

Does anyone have an idea how it should look like the code that retrieves data from the collection of data, taking into account filtration made by the user.

My idea was. Get the value of the checkbox and save them in the array and the later inclusion of data from the array in the code to retrieve data from the collection using the subroutine find ().

'change .cd-checkbox-1': function(event, target) {
var x = event.target.checked;
Session.set("statevalue", x);
var array    = [];
if (Session.get("statevalue") === true) {
    $( "[name='inputCheckboxPodmiot']:checked" ).each( function( index, element ) {
      array.push( element.value );
    });
};
var arrayLength = array.length;
for (var i = 0; i < arrayLength; i++) {
    var abiRejestr = WkaRejestrAbi.find( {}, { fields: { array[i]: 1 } } );
}

}

I got the answer to " stackoverflow ":

In main.html

<template name="test">
     <input type="checkbox" id="checkbox1" name="name" value="data">Check Me
      {{showData}}
</template>

In Main.js

 var check_status='';
 //Reactive Var Initialization
 Template.main.onCreated(function (){
       check_status=new ReactiveVar({});

 });

 Template.main.helpers({
       showData : function(){
           return Collection.find(check_status.get());
       }
 });

 Template.main.events({
      "change #checkbox1" : function(){
              check_status.set({field: 'data'});
       }
 });

But how to solve the problem of data display when the checkboxes are few, and the user can select only one or all the checkboxes.

 <template name="test">
      <input type="checkbox" id="checkbox1" name="name" value="name">Check Me
      <input type="checkbox" id="checkbox1" name="surename" value="surename">Check Me 
      <input type="checkbox" id="checkbox1" name="adress" value="adress">Check Me 
      <input type="checkbox" id="checkbox1" name="city" value="city">Check Me 
      <button class="btn btn-default" type="submit">showData</button>
      <div>{{showData}}</div>
 </template>