Hi Karl,
The biggest issue I see there is what look like global variables:
Without 'var' statements in your closure, you're using implicitly-
declared global variables, which is a very bad idea. I haven't had
time to blog the last few months, but I have a post on this:
http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html
On the code, no *massive* inefficiencies jump out, but I would
probably do something like this if the list is long:
list.row.each(function(row)
{
var x, len;
for (len = aNames.length, x = 0; x < len; x++)
{
if (row.Name.toLowerCase().indexOf(aNames[x]) >= 0)
{
filterlist.row[filterlist.row.length] = row;
break;
}
}
});
I'm assuming 'filterlist' is in-scope for the closure; a global or a
local var in the enclosing function, that sort of thing.
Prototype's Enumerable module (which is mixed into Array) has a
collect method that is for this sort of thing, but I doubt it would be
more efficient than the above:
http://www.prototypejs.org/api/enumerable/collect
If you're seeing things being really slow, I suspect the problem may
be outside of the code you quoted.
HTH,
--
T.J. Crowder
tj / crowder software / com
On Oct 6, 7:26 am, kstubs <[EMAIL PROTECTED]> wrote:
> I have a JSON array list, I am matching the "Name" item against 1 or
> more items in my match array.
>
> Pseudo:
>
> for each list.item
> if item "Name" contains one and every (must match every item in array)
> then: TRUE
> return new item to filtered list
>
> Example Data:
> Apple Martini
> Gin Martini
> Slippery Nipple
> T&T
> Gin Fizz
> A Gin X Martian
>
> Example User Input:
> gin
>
> Result:
> Gin Martini
> Gin Fizz
> A Gin X Martian
>
> Example User Input:
> gin mart
>
> Result:
> Gin Martini
> A Gin X Martian
>
> My code today:
> list.row.each(function(row)
> {
> for(x = 0; x < aNames.length; x++)
> {
> found = true;
>
> if(row.Name.toLowerCase().indexOf(aNames[x]) < 0)
> found = false;
>
> if(!found)
> break;
> }
>
> if(found)
> filterlist.row[filterlist.row.length] = row;
> });
>
> Thanks for the help! My code today is working, but seems to be slow
> and maybe inefficient.
>
> Karl..
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---