Answer the question
In order to leave comments, you need to log in
How to select documents from MongoDB when one of the fields is passed empty?
<select class="form-control" id="sel1" ng-model="$ctrl.search.vendor" ng-change="$ctrl.find()">
<option value="">Все</option>
<option ng-repeat="vendor in $ctrl.vendors">{{vendor}}</option>
</select>
return Doc.find(search);
Answer the question
In order to leave comments, you need to log in
From Html, I was unable to pass an object or regular expression as a value. No matter how I try, at the output value is perceived as a string. I came up with a "so-so" solution, the main thing is that it works) Already inside the script I go through the object and recursively delete empty fields. I'm sure there is a better solution to this problem.
self.delEmptyFields = function(obj) {
for (var key in obj) {
var value = obj[key];
if (value === "" || value === null) {
delete obj[key];
} else if (Object.prototype.toString.call(value) === '[object Object]') {
self.delEmptyFields(value);
} else if ($.isArray(value)) {
for (var k in value) {
self.delEmptyFields(value[k]);
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question