How can you manually toggle a Foundation 5 dropdown in javascript (inside an emberjs app)?

蹲街弑〆低调 提交于 2019-12-12 15:08:04

问题


I am having issues getting a dropdown to be bound properly in an ember js app because I have action handlers on click inside of the list and the foundation events are conflicting.

Template name:

<a data-dropdown="groupDrop" id="groupDropdownLink" class="button radius tiny success dropdown">
   Move Selected To Group ({{selectedCount}})
</a>
<br>
<ul id="groupDrop" data-dropdown-content class="f-dropdown">
  {{#each eventGroups}}
    <li {{action 'moveToGroup' this}}><a>{{name}}</a></li>
  {{/each}}
</ul>

When I run $(document).foundation() it overrides the action handlers, and when I remove that it doesn't trigger the dropdown.

What I think I need to do is add some action handler to the a tag and then have it open up the dropdown, so I can not use the foundation handlers.


回答1:


The function you need to use to trigger the dropdown is Foundation.libs.dropdown.toggle

You pass in a jQuery object of the dropdown link to toggle it

You can solve it like this:

template:

<a data-dropdown="groupDrop" {{action 'showDropdown'}} id="groupDropdownLink" class="button radius tiny success dropdown">
   Move Selected To Group ({{selectedCount}})
</a>
<br>
<ul id="groupDrop" data-dropdown-content class="f-dropdown">
  {{#each eventGroups}}
    <li {{action 'moveToGroup' this}}><a>{{name}}</a></li>
  {{/each}}
</ul>

controller:

Ea.GroupGuestsController = Em.ArrayController.extend
  actions:

    showDropdown: ->
      Foundation.libs.dropdown.toggle($('#groupDropdownLink'))


来源:https://stackoverflow.com/questions/20909350/how-can-you-manually-toggle-a-foundation-5-dropdown-in-javascript-inside-an-emb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!