Tag: 层次结构

jQuery在特定元素之后获取DOM中的下一个匹配项

我讨厌承认它,但我一直试图弄清楚如何做到这一点。 例如假装你有以下结构: https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/… https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/… 我在一个与上面突出显示的 “foo”节点相关的jQuery事件处理程序中。 我想找到“下一个” img元素,它是一个”foo” 。 但是有2个问题。 我只想选择DOM中比我当前节点更远的“foo”元素(例如“之前的”foo,并且不需要当前的foo) 虽然我已经将嵌套显示为精确模式,但生成的代码可以嵌套在任何级别https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…因此我不能只做.parent()。parent()。parent()。siblings( ).find()https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…等 如果你可以想象每次浏览器向DOM添加一个节点时,它会递增一个计数器,并为索引分配https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…你可以检索https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…我想要的是: var here = $(this).getIndexInDOM();//eg returns 347 $(‘img.foo’).each(function(){ if($(this).getIndexInDOM() > here){//is this past our current index? doSomething($(this));//use it break; } }); .getIndexInDOM()方法显然在jQuery中不存在https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…但我很好奇是否有人有解决方案来获取我所追求的“下一个”元素。 我现在能想到的唯一解决方案是非常优雅的,并且在DOM的后半部分中会表现得非常糟糕https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/…https://stackoverflow.com/questions/3702094/jquery-to-get-next-match-in-the-dom-after-a-particular-element/… //using vanilla JavaScript var thisImg = theCurrentImageIHave;//some reference to the DOM element var found = false; for(var i=0;i<document.images.length;i++){ if(found){ […]

如何使用JavaScript为JSON / XML数据生成MLM(多级营销)树

我有一些这样的数据:(AT sql sERVER) MemberID,ParemtID,Amt,OtherInfo 1, NULL, 200,dfdsf 2, 1, 300,DFDF 3, 1, 400,DFS 4, 3, 75,NULL 现在我想要像这样构建树 : 只使用JS。 以上数据可以用JSON / XML / CSV /格式化文本传递如何只在JS中生成这样的动态树? 请不要建议PHP / .NET解决方案。 我更喜欢JQuery。

javascript:按数组表示法字符串访问对象(数组)

我想访问提供的对象,只有它的数组forms的字符串路径是已知的。 1.)有一个对象,在哪里 root[“obj1”][“obj2”] = 1; (通常情况下, root[“obj1”]…[“objN”] ) 2.)我只有字符串objectPath已知: var objectPath = ‘root[“obj1”][“obj2”]’ 3.)我不仅要读取对象,还要设置它的值,就像 objectPath = 2; //so root[“obj1”][“obj2”] === 2 我认为 eval()可能有一些选项,但它获取的是值,而不是变量; 一个人可以遍历root的所有对象,转换为“root.obj1.obj2”(事实并非如此,因为“obj1”很容易就是“obj with spaces1”)并检查给定的字符串是否等于当前对象环。 http://jsfiddle.net/ACsPn/ 相关链接: 使用点表示法字符串访问对象子属性

使用JQuery将分隔的字符串转换为分层JSON

我有一个字符串数组,通过用短划线分隔来描述父/子关系。 因此,如果鲍勃的老板是吉姆,吉姆的老板是弗雷德,那么鲍勃在阵中的入口将是“弗雷德 – 吉姆 – 鲍勃”,吉姆的入口将是“弗雷德 – 吉姆”。 我没有能力改变数据进入的方式所以我一直在寻找帮助,就像将这些值转换为JSON的最佳方式类似: { “name”: “Fred”, “children”: { “name”: “Jim”, “children”: { “name”: “Bob” } } } 任何帮助将不胜感激。 谢谢。

如何在javaScript中实现分层多级数据表?

我正在实现多级数据表而不使用任何插件或库。 我想基于javaScript,JQuery或angular js实现。 我在下面查了一个链接, 使用JavaScript遍历JSON对象树的所有节点 使用ng-repeat的嵌套表 但我的json结构与上面的链接不同。 我需要在Tree Structure UI中显示我的JSON。 我没有硬编码级别的HTML。 所有级别都应该通过javascript处理。 我已经实现了jsfiddle: http : //jsfiddle.net/varunPes/0n9fmawb/40/ JSON结构 [ { Home:{ “checkbox_view”:true, “checkbox_edit”:false, “checkbox_delete”:true } }, { “watchColorWorld”:{ “local”:{ “app-local-black”:{ “checkbox_view”:true, “checkbox_edit”:true, “checkbox_delete”:true } }, “global”:{ “app-global-red”:{ “checkbox_view”:true, “checkbox_edit”:true, “checkbox_delete”:true } }, “world”:{ “app-world-green”:{ “checkbox_view”:true, “checkbox_edit”:true, “checkbox_delete”:true } } } }, { “systemMgmt”:{ “checkbox_view”:true, “checkbox_edit”:true, “checkbox_delete”:true […]