Jquery:将 XML 节点映射到 HTML ID 元素
概括标题中要说的内容从来都不是一件容易的事...但是我们开始了...
我意识到我可能直接看到了显而易见的、可能是 JQuery 内置功能的东西。
我想要做的是:
有一个 XML 文件(本地或通过服务器)包含恰好有它们的节点 节点名称,即 HTML 中文本框的 ID 名称 即
我想通过 JQuery AJAX 调用,解析 XML 并映射节点的值 到相同节点名称的 HTML ID 元素的值...
我立即意识到有 a) 可能是插件,b) 可能是更好的概念,但我只需要映射到基本 HTML 元素..事实上我可以从技术上讲,有一些更高级的功能可以填充组合框、单选按钮等......
只是有什么想法可以遵循吗?或者是否有一个简单的 JQuery 插件可以做到这一点?
PS:我不喜欢这样的模板,因为尽管我意识到 jTemplates 的强大功能,但我真的不需要任何如此复杂/灵活的东西......
提前致谢!
never easy to encapsulate what to say in the title... but here we go...
I realise I am probably seeing straight past the obvious, and possibly built in function of JQuery.
What I am trying to do is:
Have an XML file (locally or via server) contain nodes which happen to have their
node names i.e. as ID names of say a textbox in HTML
i.e.I want to then via the JQuery AJAX call, parse the XML and map the values of the nodes
to the value of the HTML ID elements of the same node name...
I realise straight away there are a) probably plugins, b) maybe better concepts, but I only need to map to basic HTML elements.. and in fact I could technically have some more advanced features to populate say combo boxes, radio buttons etc....
Just any ideas of a path to follow? or if there is a simple JQuery Plugin to do this?
P.S: I wasn't into templates as such, because even though I realise the power of say jTemplates, I don't really need anything as complex/flexible as that...
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该可以帮助您开始 xml 解析..nodeName
是 xml 中的标签名称,您将使用它作为 html 的 id ..
jquery text 方法将返回 xml 节点的值..(仅限文本)
加载 xml 文件使用
this should get you started on xml parsing..
nodeName is the tag name in xml which you will use as id for the html ..
the jquery text method will return the value of the xml node .. (text only)
to load the xml file use
试试这个:
假设 XML 中只有 1 层嵌套。
Try this:
Assumes only 1 level of nesting in the XML.
实际上很棒的输入,谢谢大家的帮助……它让我继续前进。
再次,我意识到那里有模板引擎,但我的下一步是构建更复杂一点的东西,以便能够填充组合框、单选按钮等..只是 HTML 的基础知识..因为我正在使用 < a href="http://www.dhtmlx.com" rel="nofollow noreferrer">DHTMLX 组件 可以做任何奇特的事情..主要是因为它们似乎拥有我发现的最容易理解的 JavaScript 小部件。我知道 ExtJS 正在赶上更好的 docco、更简单的 API 等。
所以总而言之,我将拥有:
被称为名字,那么 HTML 元素将被称为名字
这将是文本、广播、组合或其他任何内容,所以我知道如何填充这些值。
这一切的主要原因是我的合作伙伴可以将页面/布局设计为纯 HTML,而不用担心 XSLT/模板...和数据简单的填充...
我确信那里一定有一些“引擎/插件”..但现在我会努力解决它...
再次感谢...
Actually great input, thanks guys for helping.. it has got me going.
Again, I realise there are templating engines out there, but my next step is to build a little more complexity to be able to say populate a combo box, radio button etc.. just the basics of HTML.. because I am using the DHTMLX components to do any fancy things.. mainly as they seem to have the easiest to understand javascript widgets I have found.. I know ExtJS are catching up with better docco, easier API's etc..
So in Summary, I will have:
is called firstname, then the HTML element will be called firstname
which will be say text, radio, combo or whatever, so I know how to populate the values.
The main reason for all of this is that my partner can just design the page/layout as pure HTML, not worry about XSLT/Templates... and the data simple is populated...
I am sure there must be some "engine/plugin" out there.. but for now I will work on it...
Thanks again...