traversal

Jquery how to find an Object by attribute in an Array

江枫思渺然 提交于 2019-12-17 10:22:10
问题 Given I have an array of "purpose" objects: //array of purpose objects: var purposeObjects = [ {purpose: "daily"}, {purpose: "weekly"}, {purpose: "monthly"} ]; (for simplicity i am omitting other attributes) Now I want to have a method that returns a specific one of the objects if a matching purpose name is found. This is not working: function findPurpose(purposeName){ return $.grep(purposeObjects, function(){ return this.purpose == purposeName; }); }; findPurpose("daily"); but it actually

Iterating over element attributes with jQuery

早过忘川 提交于 2019-12-17 07:25:51
问题 I know individual attributes can be retrieved with the attr() method, but I'm trying to iterate over all of the attributes for an element. For context, I'm using jQuery on some XML... <items> <item id="id123" name="Fizz" value="Buzz" type="xyz"> <subitem name="foo"> <subitem name="bar"> </item> <item id="id456" name="Bizz" value="Bazz" type="abc"> <subitem name="meh"> <subitem name="hem"> </item> </items> I am already able to iterate over the items with... $(xml).find('item').each(function()

reconstructing a tree from its preorder and postorder lists

佐手、 提交于 2019-12-17 05:40:54
问题 Consider the situation where you have two lists of nodes of which all you know is that one is a representation of a preorder traversal of some tree and the other a representation of a postorder traversal of the same tree. I believe it is possible to reconstruct the tree exactly from these two lists, and I think I have an algorithm to do it, but have not proven it. As this will be a part of a masters project I need to be absolutely certain that it is possible and correct (Mathematically proven

Getting a modified preorder tree traversal model (nested set) into a <ul>

早过忘川 提交于 2019-12-17 04:13:05
问题 I am trying to get my data which is hierarchically set up with a tree traversal model into an < ul> in order to show on my site. Here is my code: function getCats($) { // retrieve all children of $parent $query = "SELECT max(rght) as max from t_categories"; $row = C_DB::fetchSingleRow($query); $max = $row["max"]; $result ="<ul>"; $query = "SELECT * from t_categories where lft >=0 and rght <= $max"; if($rs = C_DB::fetchRecordset($query)){ $p_right =""; $p_left =""; $p_diff=""; while($row = C

jquery find closest previous sibling with class

烂漫一生 提交于 2019-12-17 02:30:40
问题 here's the rough html I get to work with: <li class="par_cat"></li> <li class="sub_cat"></li> <li class="sub_cat"></li> <li class="par_cat"></li> // this is the single element I need to select <li class="sub_cat"></li> <li class="sub_cat"></li> <li class="sub_cat current_sub"></li> // this is where I need to start searching <li class="par_cat"></li> <li class="sub_cat"></li> <li class="par_cat"></li> I need to traverse from the .current_sub , find the closest previous .par_cat and do stuff to

Find all occurrences of a key in nested python dictionaries and lists

时光总嘲笑我的痴心妄想 提交于 2019-12-16 22:18:13
问题 I have a dictionary like this: { "id" : "abcde", "key1" : "blah", "key2" : "blah blah", "nestedlist" : [ { "id" : "qwerty", "nestednestedlist" : [ { "id" : "xyz", "keyA" : "blah blah blah" }, { "id" : "fghi", "keyZ" : "blah blah blah" }], "anothernestednestedlist" : [ { "id" : "asdf", "keyQ" : "blah blah" }, { "id" : "yuiop", "keyW" : "blah" }] } ] } Basically a dictionary with nested lists, dictionaries and strings, of arbitrary depth. What is the best way of traversing this to extract the

Traversing all descendants of an object

我与影子孤独终老i 提交于 2019-12-13 21:50:09
问题 I'm having problems with traversing all descendants of an object. The 'unit' in the code below is of type Unit in my program. It has a property ChildUnits which returns a List<Unit> of the children of the unit. I can successfully perform operations on the children. Then I check if those children have children, and if they do I can perform operations on them as well. However, I need to check all descendants in case there is more depth than just grandchildren. I had a go with while loops in

ViewNotFound while Ajax and Pyramids

老子叫甜甜 提交于 2019-12-13 20:12:40
问题 I'm using Pyramid and got a strange issue. I do an ajax request AR in view A. If the request is done, the user is redirected to view B. If the user goes back to A, the ajax request AR will fail, because pyramid does not find any view for the request. If someone needs code, I'll post it ;-) Thx & Greetings Tobias Edit: Snippet of my init .py # adding all routes config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('main_page', '/') config.add_route('main_contact', '

find xml element by attribute

别来无恙 提交于 2019-12-13 15:30:36
问题 Using JQuery or Javascript how would I return 'Mary Boone' from the xml below starting out with the show 'id' attribute of '2'? I'm thinking something along the lines of - var result = xml.getElementByAttribute("2").gallery.text(); the XML: <shows> <show id="1"> <artist>Andreas Gursky</artist> <gallery>Matthew Marks</gallery> <medium>photography</medium> </show> <show id="2"> <artist>Eric Fischl</artist> <gallery>Mary Boone</gallery> <medium>painting</medium> </show> </shows> 回答1: With jQuery

Use threads when traversing a tree

谁说胖子不能爱 提交于 2019-12-13 12:18:46
问题 I will like to speed the process of traversing a tree. Here is an example of a node: class Node { public List<Node> Children { get; set; } public int SompeProperty { get; set; } public String SomeOtherProperty { get; set; } } the way I traverse the try is like: static void TraverseTree(Node ParentNode) { if (ParentNode.Children == null) return; foreach (var child in ParentNode.Children) { TraverseTree(child); } } the ParentNode.Children method takes about 1 millisecond because a Node