I'm trying to create an object structure like this "price": { "minPrice": 1000, "maxPrice": 10000 }, from a dot nation passed in a URL ( price.minPrice=4000 ). "price" could be any value passed from the first part of the notation.
I using the code below but it wont create the required out come. Also when I update the value if should return "price": { "minPrice": updatedvalue , "maxPrice": updatedvalue } not { "minPrice": updatedvalue} or { "maxPrice": updatedvalue }
function getUrlDotNotation(key, value) {
var arr = key.split('.'),
var label = arr[0],
queryParams = {};
for (var i = 0; i < arr.length - 1; i++) {
vm.queryParams = vm.queryParams[arr[i]] = {};
}
vm.queryParams[arr[arr.length - 1]] = value;
return vm.queryParams;
}
$scope.$watch('vm.modelMin', function onSliderMinChange(newValue, oldValue) {
if (isSearchResultsPage) {
if (newValue !== oldValue && !_.isNaN(newValue) && !_.isNaN(oldValue)) {
getUrlDotNotation(vm.firstHandleBackendVar, vm.options[newValue].value);
}
}
});
$scope.$watch('vm.modelMax', function onSliderMaxChange(newValue, oldValue) {
if (isSearchResultsPage) {
if (newValue !== oldValue && !_.isNaN(newValue) && !_.isNaN(oldValue)) {
getUrlDotNotation(vm.secondHandleBackendVar, vm.options[newValue].value);
}
}
});