Node.js/Express Partials 问题:不能嵌套太深?

发布于 2024-08-31 23:54:13 字数 1050 浏览 3 评论 0原文

我正在学习 Node.js、Express、haml.js,并且很喜欢它们。不过我遇到了一个非常烦人的问题。我对此还很陌生,但到目前为止已经取得了不错的结果。

我正在编写一个依赖于包含 div 的表的 jquery 重型 Web 应用程序。 div 左右滑动、切换回第四个并调整大小等,以满足我的需求。

我正在寻找一种切换(模板?)div 的方法。由于我一直在快速构建并模仿聊天示例,因此使用部分内容是有意义的。问题是我一直在 haml 中使用不明确的 div,并将其保存在 td 中。 div 的结构如下:

%tr
  %td
    .class1.class2.class3.classetc

跨浏览器运行良好。解析类对于 js 代码传递参数、获取值等非常有用。

我想要做的是这样的:

 %tr
      %td
        .class1.class2.class3.classetc
           %ul#messages
             != this.partial('message.html.haml', { collection: messages })

但是,我尝试过的任何组合都失败了。我可能已经尝试过所有这些。

如果我可以将部分内容放入该 div 中,我可能会被设置。只要使用#ids 而不是.classes,就可以嵌套它们。但如果你使用多个类,它就会崩溃!我认为这是最准确的总结方式。

你如何做到这一点?我已经检查了各种模板解决方案,例如 mu.js 和微模板,例如 John Resig<​​/一个>。我之前检查过这个模板引擎线程。我很可能在这里犯了一些根本性的错误,我对此很陌生。

有什么好的方法可以做到这一点?

I'm learning Node.js, Express, haml.js and liking it. I've run into a prety annoying problem though. I'm pretty new to this but have been getting nice results so far.

I'm writing a jquery heavy web app that relies on a table containing divs. The divs slide around, switch back and fourth and are resized etc to my hearts content.

What I'm looking for a way to switch (template?) the divs. Since I've been building in express and mimicking the chat example it would make sense to use partials. The rub is that I've been using inexplicit divs in haml, held within a td. The divs are cunstructed as follows:

%tr
  %td
    .class1.class2.class3.classetc

Which has worked fine cross browser. Parsing the classes works great for the js code to pass arguments around, fetch values etc.

What I'd like to be able to do is something like:

 %tr
      %td
        .class1.class2.class3.classetc
           %ul#messages
             != this.partial('message.html.haml', { collection: messages })

Any combination I've tried with this has failed however. And I might have tried them all.

If I could put a partial into that div I'd probably be set. And you can nest them as long as you use #ids instead of .classes. But if you use more than one class it breaks! I think that's the most accurate way of summing it up.

How do you do this? I've checked out various templating solutions like mu.js and micro template like by John Resig. I earlier checked out this thread on templating engines. It's very possible I'm making some fundamental mistake here, I'm new to this.

What's a good way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2024-09-07 23:54:13
%li= message

为了部分权利?
确保您拥有视图文件夹中的partials 文件夹的路径。
您可能想检查正在传递的消息。即先让它在没有部分的情况下工作。

%li= message

For the partial right?
Ensure you have the path to the partials folder in the view folder.
You might want to check messages is being passed. Ie get it working without the partial first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文