Hey all,
In the below javascript, "this" refers to Car object and search_id refers to the input text field with an id of "search_input". So basically the user types in text in the field and a search occurs based on the input. Now I understand that the val() method is grabbing the user input string from the input field. However, I am not sure what the colon in the split() method is doing. I always thought the split() method just puts a comma delimiter when you pass in an empty string into it. And then it appears that the splitted variable holds an array of strings broken down from the input. However, why would we be passing in the first broken down string in the string array (splitted[0]) and the second string (splitted[1]) and then passing that into the variable string_to_scope? Basically it is in the process of building a search. And it's these three lines I'm not sure what's going on:
var splitted = jQuery(this.search_id).val().split(": ");
if (splitted[0] && splitted[1]){
if (string_to_scope[splitted[0]]) ret[string_to_scope[splitted[0]]] = splitted[1];
Here's more context:
Car.prototype.filter_func=function(){
var ret={};
var string_to_scope = {
'Year': 'year_num_eq',
'Make': 'make_name_eq',
'Description': 'description_eq',
'Expiry': 'expires_on_eq'
};
var search_value = jQuery(this.search_id).val();
if(search_value != null && search_value.length > 0){
var splitted = jQuery(this.search_id).val().split(": ");
if (splitted[0] && splitted[1]){
if (string_to_scope[splitted[0]]) ret[string_to_scope[splitted[0]]] = splitted[1];
}
}
return ret;
};
Thanks for any response.