Error in DomQuery - Ext JS

本文探讨了在使用ExtJS构建动态菜单时遇到的一个JavaScript错误,并提供了一个示例代码。作者建议增加一个新函数Element.children()来更方便地选择直接子元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I get the following javascript error in the example code at the end of this post.

cs has no properties
nodup(undefined)ext-all-debug.js (line 748)
(no name)(li)ext-all-debug.js (line 892)
select("ul:first", li, undefined)ext-all-debug.js (line 912)
selectNode("ul:first", li)ext-all-debug.js (line 922)
child("ul:first", undefined)ext-all-debug.js (line 2126)
(no name)()from-markup.html (line 26)
each(function(), undefined)ext-all-debug.js (line 4544)
constructMenu(Object dom=ul#ext-gen8 id=ext-gen8 visibilityMode=1, undefined)from-markup.html (line 15)
(no name)()from-markup.html (line 28)
each(function(), undefined)ext-all-debug.js (line 4544)
constructMenu(Object dom=ul#menu-main id=menu-main visibilityMode=1, function())from-markup.html (line 15)
(no name)()from-markup.html (line 37)
fire()ext-all-debug.js (line 1382)
fireDocReady()ext-all-debug.js (line 1411)
[Break on this error] var len = cs.length, c, i, r = cs, cj;
When using Element.child("tagname:first"). Here's the "menu from markup" example I posted in that other thread, using Element.child("ul:first") (which would be a little more elegant than using .select and checking the length of the array):

Could I also suggest a new function Element.children()? Element.select("li") produced all descendant <LI> elements. What is needed is direct children. I used Element.select(">li"), but a children() function alongside child() which only selected from the child nodes would be nice.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Menu from markup</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../yui-utilities.js"></script>
<script type="text/javascript" src="../../ext-yui-adapter.js"></script>
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript">
function constructMenu(e, clickHandler) {
  e = Ext.get(e);
  var items = [ ];

  e.select('>li').each( function() {
    // set current item properties
    var link = this.child('a:first', true);
    var currentItem = {
      text: link.innerHTML,
      cls: link.className,
      id: link.id,
      handler: clickHandler,
    };

    // Check for sub menu.
    var s = this.child('ul:first');
    if (s) {
      currentItem.menu = {items: constructMenu(s, clickHandler)};
    }
    items.push(currentItem);
  });

  return items;
}

Ext.onReady(function() {
	var m = new Ext.menu.Menu({id: "the-menu", items: constructMenu("menu-main", function(){alert("clicked")})});
	Ext.get("menu-main").remove();
	m.render();
	m.show(Ext.get("container"));
});
</script>
</head>
<body>
<h1>Menu from markup</h1>
<div id="container">
</div>
<ul id="menu-main">[*]
    <a class="menu-top">Simple Menu</a>
    <ul>[*]<a>item 1b</a>[*]<a>item 2b</a>[*]<a>item 3b</a>[*]<a>item 4b</a>[/list]  
 [*]
    <a class="menu-top">Nested menu</a>
    <ul>[*]<a id="item1">item 1</a>[*]<a id="item2">item 2</a>[*]<a id="item3">item 3</a>
        <ul>[*]<a>subitem a</a>[*]<a>even another level</a>
             <ul>[*]<a>foo</a>[*]<a>bar</a>[*]<a>lorem</a>[*]<a>ipsum</a>[/list]          [/list]      [*]<a id="item4">item 4</a>[/list]  [/list]</body>
</html>
Reply With Quote
  #2  
Old 03-16-2007, 06:25 AM
Default

I like the direction this example is headed in.

Using > or / to get direct children is the default way primarily because you can use that same syntax to go multi levels deep with children. e.g. el.child('/ul.foo/li.bar') or el.child('> ul.foo > li.bar'). Plus do we really want a seperate function just to prepend a > or / ?

The error you are receiving has been fixed. I ran into it to. The problem was n becomes undefined if there is no first (or nth and others). I will have new rev soon with the fix.
Reply With Quote
内容概要:本文详细介绍了Rust在系统编程中的应用,包括基础知识、核心技术及开发流程。首先阐述了Rust语言的基础及环境搭建,强调了其强类型系统和现代语法。接着深入探讨了所有权机制与内存安全,指出Rust通过所有权系统确保内存安全,避免悬垂指针和内存泄漏。再者,讲解了Rust的并发编程模型,通过消息传递和无数据竞争的线程模型实现安全并发。此外,讨论了Rust在底层硬件访问与嵌入式开发中的应用,展示了其在资源受限平台上的适应性。随后,介绍了系统调用与内核模块开发,说明了Rust如何调用操作系统底层API并实现与现有内核代码的无缝集成。还提及了性能优化与调试技巧,如使用编译器优化选项和工具链支持。最后,通过实战项目案例解析和社区资源展望,展示了Rust在系统编程领域的潜力和发展前景。; 适合人群:有一定编程基础,尤其是对系统编程感兴趣的开发者,包括操作系统内核开发、驱动程序编写、嵌入式系统开发等领域的工程师。; 使用场景及目标:①学习Rust语言的基础知识和环境搭建,掌握强类型系统和现代语法;②理解所有权机制与内存安全,避免传统系统编程中的常见错误;③掌握并发编程模型,实现安全高效的多线程操作;④了解底层硬件访问和嵌入式开发,适应资源受限平台;⑤掌握系统调用与内核模块开发,实现与现有系统的无缝集成;⑥学习性能优化与调试技巧,提高系统软件的运行效率和稳定性;⑦通过实战项目案例解析,掌握系统编程的实际应用。; 其他说明:Rust作为系统编程的新选择,不仅提升了传统系统软件的安全性,还通过现代语言特性和工具链优化了开发效率。开发者应充分利用Rust的特性,构建更加健壮、高效的系统软件,迎接未来计算机领域的新挑战。
资源下载链接为: https://pan.quark.cn/s/67c535f75d4c 网页表单设计是提升网站互动性和用户体验的关键环节,它不仅是用户与网站沟通的重要桥梁,还能高效地收集信息。本文将深入剖析40多个出色的网页表单设计案例,探讨现代设计策略和创新思维。 简洁明了的设计是表单的核心。设计者需确保用户能够轻松理解表单字段的功能,避免复杂或冗长的表单给用户带来负担。例如,Softmails的通讯框通过融合邮件图标和简洁的提交按钮,打造了美观易用的界面。Swfir和Katrin Wegmann的网站则分别借助信封和手写元素,提升了表单的视觉吸引力。 创新设计可以为表单注入趣味性和互动性。Created 201.com的立体联系表单利用Flash技术创造出独特的视觉效果,而Edward Pistachio的网站通过解谜游戏增加了互动性。Chemistry Recruitments的文件夹和便签设计,以及Alexandru Cohaniuc的草纸与邮票组合,都为表单增添了生活气息。 巧妙运用插图和文字也能增强表单的亲和力。Intuitive Designs的邮递员形象和X-Grafik.sk的斯洛伐克邮票设计,以生动的方式吸引用户注意力。Kqoule.com的小助手和DressforDialoge.com的微小插画,虽尺寸不大,但效果显著。 集成更多功能是现代网页表单设计的趋势。例如,InfectedFx的表单集成了提示、选择项和WYSIWYG编辑器,而Sidebarcreative.com则通过滑杆让用户设定项目预算。这些功能不仅提升了表单的实用性,也优化了用户体验。 使用图标传达必填信息也是一种提升表单易用性的方法。通过视觉提示,用户可以快速了解哪些字段是必填的,从而减少填写过程中的困惑。 网页表单设计需要在美观、实用和创新之间找到平衡。通过简洁的布局、巧妙的插图应
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值