UIKit accordion and ng-repeat doesn't work

独自空忆成欢 提交于 2020-01-03 05:32:09

问题


I'm adding new accordion sections to my UIKit data-uk-accordion dynamically, using ng-repeat.

<div class="uk-accordion" data-uk-accordion="{ collapse: false }">
  <h3 class="uk-accordion-title uk-active" ng-repeat-start="driver in drivers">Driver {{driver.id}}</h3>
  <div class="uk-accordion-content" ng-repeat-end>
  ...
</div>

When I add new accordion sections and I click on the title to collapse, I'm getting the following error:

TypeError: wrapper is undefined, on line 73 of accordion.js in UIkit 2.24.2: wrapper.data('toggle').toggleClass(this.options.clsactive);

I tried adding data-uk-observe to the accordion div, or its parent divs but didn't have any effect, and also tried to reinit the accordion manually by adding it an id, and running UIkit.accordion('#drivers') from console but no change.

Even tried to run UIkit.init() from console but I'm getting the same error.

Any ideas how to reinit the accordion?


回答1:


It looks like what you want to do is:

  • Omit the data-uk-accordion attribute.
  • Save the object returned from calling UIkit.accordion(element, options).
  • After new accordion child elements have been added, call accordion.update(). (assuming you saved the returned object above in a variable called accordion)

For more information about how I arrived at that, check out the related issue on GitHub.



来源:https://stackoverflow.com/questions/34189220/uikit-accordion-and-ng-repeat-doesnt-work

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