When parsing XML with jquery, how can we pass the current node from within each() to another function and vice-versa
Say we have an XML document with many book nodes...
When parsing XML with jquery, how can i pass the current node from each() iteration to another function that will do some stuff until something is reached and then go back to the previous function (passing along the current node from this function back to the first function)?
Here something more descriptive (this is just an example out of my head, not accurate):
function MyParser(x1,x2,dom)
{
// if i am called by anotherFunction(thisNode) proceed from the passed node
dom.find('book').each(function()
{
var Letter = thisNode.find(author).charAt(0);
if(x1 == Letter)
开发者_高级运维 {
// print everything till the next letter (x2)
anotherFunction(thisNode)
}
}
}
function anotherFunction(x2,thisNode)
{
//continue parsing here until you reached x2
//when x2 is reached, return to previous function passing again the current node
}
Something like this? Your node
will still be on scope.
var f1=function(node){
// do stuff
}
var f2=function(node){
// do stuff with node
$('query').each(
function(){
f1(node);
}
);
// continue doing stuff with node
}
If you want to be explicit you could have f1
return node:
var f1=function(node){
// do stuff
return node;
}
Correct me if I am misunderstanding. I am not sure if you want to return to the first function or call the first function again.
精彩评论