本文介绍了UIKit 手风琴和 ng-repeat 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ng-repeat 动态地向我的 UIKit data-uk-accordion 添加新的手风琴部分.

<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>...

当我添加新的手风琴部分并单击标题折叠时,出现以下错误:

TypeError: wrapper is undefined, 在 UIkit 2.24.2 中的手风琴.js 的第 73 行:wrapper.data('toggle').toggleClass(this.options.clsactive);

我尝试将 data-uk-observe 添加到手风琴 div 或其父 div 但没有任何效果,还尝试通过添加 id 手动重新初始化手风琴,并且从控制台运行 UIkit.accordion('#drivers') 但没有变化.

甚至尝试从控制台运行 UIkit.init() 但我遇到了同样的错误.

任何想法如何重新启动手风琴?

解决方案

看起来你想做的是:

  • 省略 data-uk-accordion 属性.
  • 保存调用UIkit.accordion(element, options)返回的对象.
  • 添加新的手风琴子元素后,调用accordion.update().(假设您将上面返回的对象保存在名为 accordion 的变量中)

有关我如何实现这一点的更多信息,请查看 GitHub 上的相关问题.

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?

解决方案

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.

这篇关于UIKit 手风琴和 ng-repeat 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:07