traversal

Converting JavaScript 'this' to jQuery '$(this)'

房东的猫 提交于 2019-12-18 21:14:56
问题 Please have a look at the following code: <HTML> <HEAD> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <SCRIPT type="text/javascript"> function test(target) { alert(target.nodeName); } </SCRIPT> </HEAD> <BODY> <DIV> <ul> <li onclick="test(this)">This is fair</li> <li onclick="test(this)">No its not</li> <li onclick="test(this)">Why not</li> <li onclick="test(this)">Becoz...</li> </ul> </DIV> </BODY> </HTML> The function test receives

Traverse the DOM tree

≯℡__Kan透↙ 提交于 2019-12-18 13:19:43
问题 As most (all?) PHP libraries that do HTML sanitization such as HTML Purifier are heavily dependant on regex, I thought trying to write a HTML sanitizer that uses the DOMDocument and related classes would be a worthwhile experiment. While I'm at a very early stage with this, the project so far shows some promise. My idea revolves around a class that uses the DOMDocument to traverse all nodes in the supplied markup, compare them to a white list, and remove anything not on the white list. (first

Traversing FTP listing

自作多情 提交于 2019-12-18 06:57:33
问题 I am trying to to get all directories' name from an FTP server and store them in hierarchical order in a multidimensional list or dict So for example, a server that contains the following structure: /www/ mysite.com images png jpg at the end of the script, would give me a list such as ['/www/' ['mysite.com' ['images' ['png'], ['jpg'] ] ] ] I have tried using a recursive function like so: def traverse(dir): FTP.dir(dir, traverse) FTP.dir returns lines in this format: drwxr-xr-x 5 leavesc1

Traversing FTP listing

跟風遠走 提交于 2019-12-18 06:57:04
问题 I am trying to to get all directories' name from an FTP server and store them in hierarchical order in a multidimensional list or dict So for example, a server that contains the following structure: /www/ mysite.com images png jpg at the end of the script, would give me a list such as ['/www/' ['mysite.com' ['images' ['png'], ['jpg'] ] ] ] I have tried using a recursive function like so: def traverse(dir): FTP.dir(dir, traverse) FTP.dir returns lines in this format: drwxr-xr-x 5 leavesc1

DOM: fetch all text nodes in the document (PHP)

為{幸葍}努か 提交于 2019-12-18 06:53:58
问题 I've have the following (PHP) code that traverses an entire DOM document to get all of the text nodes. It's a bit of a ugly solution, and I'm sure there must be a better way... so, is there? $skip = false; $node = $document; $nodes = array(); while ($node) { if ($node->nodeType == 3) { $nodes[] = $node; } if (!$skip && $node->firstChild) { $node = $node->firstChild; } elseif ($node->nextSibling) { $node = $node->nextSibling; $skip = false; } else { $node = $node->parentNode; $skip = true; } }

Getting nested set model into a <ul> but hiding “closed” subtrees

a 夏天 提交于 2019-12-17 22:53:19
问题 Based on Getting a modified preorder tree traversal model (nested set) into a <ul> One of answers gave right code to display full tree. What i need is to always show first level (depth=0) and siblings+childrens for active list item. Goal is to expand visible part of tree when user selects list item which is parent for more list items. So, if i got this list: 1. item 2. item 2.1. item 2.2. item 2.2.1. item 2.2.2. item 2.2.3. item 2.3. item 2.4. item 2.4.1. item 2.4.2. item 3. item 4. item 4.1.

How do you iterate backwards through an STL list?

て烟熏妆下的殇ゞ 提交于 2019-12-17 18:06:01
问题 I'm writing some cross-platform code between Windows and Mac. If list::end() "returns an iterator that addresses the location succeeding the last element in a list" and can be checked when traversing a list forward, what is the best way to traverse backwards? This code workson the Mac but not on Windows (can't decrement beyond first element): list<DVFGfxObj*>::iterator iter = m_Objs.end(); for (iter--; iter!=m_Objs.end(); iter--)// By accident discovered that the iterator is circular ? { }

Write a non-recursive traversal of a Binary Search Tree using constant space and O(n) run time

别等时光非礼了梦想. 提交于 2019-12-17 17:24:48
问题 This is not homework, this is an interview question. The catch here is that the algorithm should be constant space. I'm pretty clueless on how to do this without a stack, I'd post what I've written using a stack, but it's not relevant anyway. Here's what I've tried: I attempted to do a pre-order traversal and I got to the left-most node, but I'm stuck there. I don't know how to "recurse" back up without a stack/parent pointer. Any help would be appreciated. (I'm tagging it as Java since that

Prolog, find minimum in a list

痴心易碎 提交于 2019-12-17 16:55:41
问题 in short: How to find min value in a list? (thanks for the advise kaarel) long story: I have created a weighted graph in amzi prolog and given 2 nodes, I am able to retrieve a list of paths. However, I need to find the minimum value in this path but am unable to traverse the list to do this. May I please seek your advise on how to determine the minimum value in the list? my code currently looks like this: arc(1,2). arc(2,3). arc(3,4). arc(3,5). arc(3,6). arc(2,5). arc(5,6). arc(2,6). path(X,Z

Jquery how to find an Object by attribute in an Array

痞子三分冷 提交于 2019-12-17 10:23:09
问题 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