mercredi 28 septembre 2016

angularjs build search criteria with check boxes

Forgive the noob angular question:

I am attempting to aggregate product search terms using check boxes. When a user selects/deselects an check box, the values are returned and filter the product list...

My initial approach was to hard code the product categories and then run a ng-click function that iterated the categories and built the search string... i.e. (product=controllerAs syntax)

<input ng-click="product.changeSearch()" ng-model="product.criteria.form.liquid">
<input ng-click="product.changeSearch()" ng-model="product.criteria.form.solid">

Then on the controller side:

vm.changeSearch = function() {
_.map(vm.criteria.forms, function(criteria) {
        if (criteria) {
            criteriaCompiled.push(criteria);
        }

        console.log('criteria: ', criteriaCompiled);
    });

The ideal output would be "mongo-ready" such that I can run a find.{ form: "Liquid, form: "Solid" } query.

I'm thinking this is the wrong strategy because I have about 20 elements to choose from and the array is proving difficult to map and return meaningful values, especially when looking at true/false checkbox values...

Any practical or theoretical advise is appreciated...




Aucun commentaire:

Enregistrer un commentaire