简体   繁体   English

使用Rails link_to标记将div转换为HAML中的链接,其中包含嵌套内容

[英]Turn a div into a link in HAML using a Rails link_to tag, with nested content within

Sorry if this question doesn't make too much sense. 对不起,如果这个问题没有多大意义。 I have a dropdown menu which expands. 我有一个扩展的下拉菜单。 The first link in the menu that I want to expand on will be called "Overview". 我要扩展的菜单中的第一个链接将被称为“概述”。 I want to use a link_to_function tag to expand the items below Overview. 我想使用link_to_function标记来展开Overview下面的项目。 However, I want the first link to say "Overview +" all on one line, with the "+" later changing to a "-" once the menu has expanded. 但是,我希望第一个链接在一行中显示“Overview +”,一旦菜单扩展,“+”稍后会更改为“ - ”。 I also want the +/- to be justified right, and "Overview" to be justified left. 我还希望+/-被证明是正确的,而“概述”是合理的。 I've already implements the +/- change. 我已经实现了+/-更改。

How can I do something like the following? 我该如何做以下事情? Haml won't allow me to nest the links like this. 哈姆不允许我像这样嵌套链接。 The +/- change has already been implemented, so that part is working. +/-更改已经实现,因此该部分正在运行。

#main.section= link_to_function 'Overview', "toggleMenu('#main')"
  %a +
  %a -

Basically, I want the overall div to be the actual link, while the nested %a tags within are just there for formatting purposes. 基本上,我希望整个div是实际的链接,而嵌套的%a标签只是用于格式化目的。 Of course, I could easily use JavaScript to put a listener on #main, but I want this to be dynamic so that I can expand multiple sections of the menu the same way. 当然,我可以轻松地使用JavaScript在#main上放置一个监听器,但我希望它是动态的,这样我就可以用同样的方式扩展菜单的多个部分。

You can pass a do/end block to the link_to method: 您可以将do/end块传递给link_to方法:

= link_to home_path do
  %span= "Go to"
  %span= "Home!"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM