Get all unselected nodes in dynatree - javascript

I have implemented dynatree. I can get all selected nodes simply by:
$("#tree").dynatree("getSelectedNodes");
How can I similarly get all unselected nodes?

$('#tree') will give you an array of all the nodes. And your code here will give you an array of selected nodes. You can loop through the main tree nodes array and generate a new array by checking if the node in a particular iteration does not match with selected nodes array.

Related

nth parent of each filtered element in Jquery

I have a requirement where I need to find out 4th parent for each filtered item from jQuery.
$("a.dropdown-toggle").filter(function() {
return $(this).text().indexOf('ADD_DELET') > -1
}).parents().eq(4);
If the above filter function is returning single value , above code is working fine but if the filter function is returning more than one item. Above code is not working.
.eq(4) is selecting element 4 from all the parents of all selected dropdowns, not the 4th parent of each.
Use a .each() loop that adds the appropriate parent to a collection.
There's also no need to use filter(), you can use the :contains() selector.
let parents = $([]); // empty collection
$("a.dropdown-toggle:contains(ADD_DELET)").each(function() {
parents = parents.add($(this).parents().eq(4));
});
It would be easier if you gave those parents a unique class, then you could use .closest():
let parents = $("a.dropdown-toggle:contains(ADD_DELET)").closest(".classname");
This is more robust than counting parents, since it won't break if the organization is modified to add or remove nesting levels.

Mongoose find if an array element is in another array

How do I check if an element of an array belongs to another array in Mongoose.
For example, I have a document:
{"_id":"","username":"","password":"","email":"","image":"1-81-14.svg","dob":"","marital_status":"","phone":"","categories":["catering_services","legal_services","computer_programmers","rentals","fashion_designers","education"]}
and another document of the same collection:
{"_id":"","username":"","password":"","email":"","image":"1-81-14.svg","dob":"","marital_status":"","phone":"","categories":["computer_programmers","rentals","fashion_designers","education", "music"]}
How do I check if at least an element of the array in the categories node in the first document belongs to the array in the second document

select multiple array elements at once

a very basic Array question but I don't know how to do this in the best possible way.
I have an array
var pathArr = [element1, element2, element3, element4, element5, element6]
what can I do if I want to select multiple elements of this path at once.
Lets say:
pathArr[0-2].dofunction()
in this example I'm doing the function on the first three elements.
or
pathArr[1,6].dofunction()
in this example only on element1 and element6
Is there something I can do with an array?
No.
Iterate through your array and apply your method to each appropriate item.
You could use slice to return a range of items in an array, which might make it easier for you, depending on what you're doing.

How to assign a unique id to a node in d3 collapsible tree

As someone new to d3 and javascript, I am trying to learn how the collapsible tree works by looking at the version provided by
http://bl.ocks.org/mbostock/4339083
Specifically, I do not understand how and why the following statement successfully assigns a unique id to a node after nodes have been updated.
// Update the nodes…
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
My understanding is that nodes is an array, and this array has an associated index i.
Each time the nodes is updated, the above statement binds the new nodes(as in data) with the nodes on the webpage (as in visual representation) using the unique key value of id derived from the array index i. If an element of the nodes array does not have an id, it will be assigned ++i.
This is where I get confused. Suppose the first nodes array has 4 elements so each element gets an id of 1,2,3, and 4. I collapse the tree and now the new nodes array has 3 elements that happen to be the same first three elements of the first nodes array. These elements have an id of 1,2 and 3. No problem so far.
Now the next updated nodes array has 4 elements with the same first 3 and a different 4th element.
The above code correctly assigns an id of 5 to this 4th element.
My understanding is
this last nodes array has 4 elements,
index i for this new 4th element = 3, and
++i = 4
As a result, the above statement should have assigned an id of 4 to the 4th elements.
But the code assigns id=5 instead. And when I check the value of i in the firebug debugger, i goes up to 4, remains at 4, and then goes to 5 for the above scenario.
Can someone explain what is happening with the above code and where my faulty understanding lies?
Thank you.
The variable i used in the particular example you're referring to is, as opposed to almost all other D3 examples, a global counter that keeps track of how many nodes have been seen. In many other cases, you would see code like
.attr("something", function(d, i) { ... })
or
.data(data, function(d, i) { ... })
In all of these cases, i refers to a variable local to the function -- the index of the data element within its array. This is passed by D3 and a completely different i than the one in the example you're referring to.
It might help to understand the example better if you replace all occurrences of the i with counter.

Titanium- JavaScript : How to set check mark of a particular row if the values of row existed in a selected array

I was very new to titanium and java script
I have populated a table view with an array myArray
as follows
$.table.setData(myArray);
in that myArray contains JSon formatted values like (title:value1, title:value2)
And i have an another array 'selectedArray' of selected values
Now i need to check each row values that it was existed in 'selectedArray' or not
if it was already existed in 'selectedArray' then we need to disply a check marK
how to achieve this can any one help me
There are 2 basic ways:
You can maintain single array and add a field named selected (true/false)
While adding the elements to myArray you can check for same element in selectedArray and add checkmark accordingly

Categories

Resources