jQuery:模板化数据
我有一个独特的情况,我正在构建一个网站,该网站将通过 AJAX 调用数据并将其加载到“容器”中(基本上只是根据从 AJAX 回调检索的元素进行样式设置和排列的 div)。
我不确定当一切都完成后,将创建多少个独特的容器类型(样式化和渲染),因此我正在寻找一种解决方案,允许我将容器存储在一个单独的文件,根据需要动态加载它们,填充内容,并将它们呈现在页面上。
我不确定是否应该编写自己的加载/模板解决方案或使用现有的 JavaScript 模板引擎(例如:Pure)。
我对使用现有 JavaScript 模板解决方案犹豫不决的原因是它们似乎都专注于现有页面元素的绑定和循环,而我更关心加载和绑定到动态内容的能力。
I have a unique situation where I'm building a site that will call data via AJAX and load it into "containers" (basically just divs styled and arranged according to elements retrieved from the AJAX callback).
I'm not sure how many of these unique container types will be created (styled and rendered) when all is said and done, so I'm looking for a solution that will allow me to store containers in a separate file(s), load them dynamically as they are needed, populate the content, and rendered them on page.
I'm not sure if I should write my own loading/template solution or use an existing JavaScript template engine (e.g.: Pure).
The reason I'm hesitant to use an existing JavaScript template solution is they all seem focused on binding and looping on existing page elements, whereas I'm more concerned with the ability to load-up and binding to dynamic content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想尝试一下 jQote,它是最强大的 jQuery 模板引擎,因为它允许您在模板中使用脚本。
去看看吧,我保证它会满足你的需求。
http://aefxx.com/jquery-plugins/jqote
You might want to give jQote a try, it's the most powerful jQuery templating engine as it let's you use scripting inside your templates.
Go check it out, it'll suit your needs, I promise.
http://aefxx.com/jquery-plugins/jqote
从 JST 开始之后,我们转向了 EJS:
http://embeddedjs.com/
它更强大,语法更简单,您可以将模板放在不同的文件中。
该网站也很不错。
After starting with JST, we moved to EJS:
http://embeddedjs.com/
It's more powerful, syntactically simpler, and you can put your templates in different files.
The website is pretty nice too.
我发现http://code.google.com/p/trimpath/wiki/JavaScriptTemplates< /a> 对此非常有用。
I found http://code.google.com/p/trimpath/wiki/JavaScriptTemplates pretty useful for this.
我计划在未来的项目中使用 jTemplates ,该项目需要做这样的事情,它非常快并且有一个不错的 jQuery 插件
I am planning to use jTemplates for a future project that will need to do something like this, it is very fast and has a nice jQuery plugin