ExtJS Find Node within Tree Branch - extjs

I'm trying to check whether a certain node exists beneath a branch of an ExtJS tree. Knowing the ID of the parent node, is there a library function to check whether a node exists beneath the parent (by its ID)?
I've checked the API numerous times over, and can only seem to accomplish this by iterating through the entire branch of the tree.
Is there a library function which allows me to check if a child exists (by its ID) if the parent node ID is known?
Thanks!
PS, to find the parent ID, I'm using the following:
tree.getNodeById('myID');

Ext.tree.TreeNode "contains" function does exactly what you want:
var parent = tree.getNodeById('myID');
parent.contains(tree.getNodeById('childId'));

Have you looked at DomQuery? The API defines the method jsSelect: selects a group of elements.
jsSelect( String selector, [Node/String root] ) : Array
Parameters:
selector : String
The selector/xpath query (can be a comma separated list of selectors)
root : Node/String
(optional) The start of the query (defaults to document).
Returns an Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.

Related

How do I use the last value in an array as a path for .child() when retrieving a snapshot?

I'm new to Firebase and have a function that writes all of my event ID's to an array. I want to use the last value in that array (the last event ID) to lookup the children of that specific eventID.
I know how to get the last item in the array but how do I put that into my .child() path?
I tried the code below, but it doesn't seem to work. I'm guessing that because .child("(lastEvent)") isn't a valid path.
let lastEvent = eventIDArray.last
refHandle = ref.child("Bouts").child("\(lastEvent)")
How do I plug the lastEvent value in as my path? Or is that even possible? Again, total newbie- alternatives welcome.
Sorting and filtering data
you can use sorting and filtering function to get the item.
To get the last item you can write the query like this.**
let recentBoutsQuery = (ref?.child("Bouts").queryLimited(toLast: 1))!
This will return 1 entry from last of your database which the last entry.
You can learn more from the firebase documentation. Work with Lists of Data

How to get the name of the list where the element is dropped

I'm using this plugin to implement a drag and drop feature in my app :
https://github.com/marceljuenemann/angular-drag-and-drop-lists
After an element is moved from a list to another one i successfully trigger a function in which i would like to retrieve : the moved element (this is working) and the name of the list in which the element is dropped, instead i have the name of the list from where the element was picked. I made a really quick function to achieve this but it doesn't work.
$scope.drop = function(liste, candidat){
//In this function we try to get the list name in which the element is dropped, for instance : suggeres, retenus_consultant, proposes, etc...
console.log(liste);
}
I made a plunker of the current state where i'm stuck at : plunker
I've been stuck for a while now and maybe someone can explain me how to do this.
Basically i understand why my function returns me the original list of the element, however i have no clue how to get the list in which the element is dropped. I assume the plugin has a way to know that since it change the datas from a list to another one.

Selecting first element verifying a condiction using xPath in libxml

In libxml, I try to select the first element to verify a condition using xpath. If I understood correctly, "//div[contains(#id,'art')][1]" in xpath would give just one element, though I get more than one of them. I use the function getnodeset in the libxml tutorial (see here). Here is the code :
xmlXPathObjectPtr result=getnodeset(def,(xmlChar*) "//div[contains(#id,'art')][1]"); // where def is a htmlDocPtr
xmlNodeSetPtr nodeset;
if(result)
{
nodeset=result->nodesetval;
if(nodeset->nodeNr>1)
fprintf(stderr,"%i first div with id attribute *art* : %s\n",nodeset->nodeNr,nomDef);
}
Instead of
"//div[contains(#id,'art')][1]"
you want
"(//div[contains(#id,'art')])[1]"
The reason has to do with binding precedence. As you probably know, [1] is shorthand for [position() = 1]. In the variant that you were trying to use, this means "when the current node (the div element) is the first child of its parent". Clearly, there could be many such divs that are each the first child of their respective parent.
When you put parentheses around the expression //div[predicate] and append [1] to that, then you're asking the question you intended to ask: what is the first node in the nodeset selected by //div[predicate]?

Xpath array for child elements

I have a an xpath code which returns multiple variable child elements
i want to be able to read each child element.
Is it possible to create an array or is there some other way to pass a wildcard into xpath to pull all child elements?
Example:
<changeSet>
<item></item>
<item></item>
<item></item>
</changeSet>
The number of items could vary.
I would like to be able to read all items that might show up when i run the query.
Well with pure XPath 1.0 the expression /changeSet/item returns a set of all item element nodes that are children of the changeSet root element. Or /changeSet/* returns all child elements of the changeSet root elements. Of course depending on the XPath API you use you might get acollection or a list or array of nodes or in the worst case only the string value of the first selected node. In that case you need to look at the XPath API you use, it should offer an option to return a collection of nodes.

How to easily grab an array of children from a batch node by tag

I know that I can get an array of all the children of a CCSpriteBatchNode by using its children property, but can I get an array easily of just the subset of children that share a common tag?
What I do now is:
Get the array of the children of the batch node
Make a new array for the children with the tag of interest
Iterate through the children, and if the individual child has that tag, add it to the new array
Seems kind of cumbersome so I thought there might be a way to to it easily. If you just want a single child, you can use getChildByTag I think...
That's the way to do it.
However you can (and should) initialize an array with the children that use the same tag in your class, and every time you add a child with that tag you'll also add it to the "childsWithTagX" array. Same for removing. That way you have an always up-to-date separate children array containing only nodes with a given tag.
I think I'll have to add this as a feature to the Kobold2D Roadmap. I needed that a few times already.

Resources