重新加载轮播项目

发布于 2024-11-15 14:16:27 字数 495 浏览 3 评论 0原文

我需要从我的传送带中重新加载项目(我单击了一个项目,一个面板被破坏,然后当我尝试返回时,我需要重建传送带)

为此,我通过执行以下操作删除传送带的项目:

var len = cards.length;
for(var c = 0; c < len;c++)
this.myCarousel[0].items.remove(cards[0]);

然后我再次设置卡片并再次设置轮播项目:

this.myCarousel[0].items.append(cards);
this.doLayout();

但是这样做之后,卡片没有设置正确,它们只是写在彼此之上,没有完成轮播效果。此外,卡片开始在轮播的工具栏下绘制,而不是在工具栏下方开始绘制。

第一次加载卡片时,它工作得很好(当我从头开始构建轮播时),但是如果我删除以前的卡片并再次添加它们,它们将无法正确显示,我希望有人可以帮助我。

先感谢您

I need to reload the items from my carousel (I clicked on an item and a panel gets destroyed, then when I try to go back, I need to rebuild the carousel)

For this I am removing the items of the carousel by doing:

var len = cards.length;
for(var c = 0; c < len;c++)
this.myCarousel[0].items.remove(cards[0]);

then I set the cards again and set the carousel items again:

this.myCarousel[0].items.append(cards);
this.doLayout();

but after doing this, the cards dont get set right, they just get written on top of each other, no carousel effect gets done. Also the cards start being drawn under the carousel's toolbar, instead of starting below the toolbar.

The first time when I load the cards it works perfectly (when I build the carousel from scratch), but if I delete the previous cards and add them again, they don't get displayed properly, I hope someone can help me.

Thank you in advance

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

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

发布评论

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

评论(2

廻憶裏菂餘溫 2024-11-22 14:16:27

在轮播本身上进行添加和删除,因为它有方法来执行此操作:

this.myCarousel.removeAll();
var items = [];
for (...) {
   items.push(<item def>);
}
this.myCarousel.add(items);
this.carousel.doLayout(); // Force the carousel to re-render
this.myCarousel.scrollToCard(0); // This will send the user back to the first card

如果当您运行上述命令时用户位于不同的卡上(例如,如果您将其放入方向检查中),那么您应该将它们返回到正确的位置像这样的卡:

var curIndex = this.myCarousel.items.items.indexOf(this.myCarousel.layout.activeItem);
// Now do removing and adding
this.myCarousel.scrollToCard(this.myCarousel.items.items[curIndex]);

您必须使用索引,因为该项目将被删除。

Do the adding and removing on the carousel itself as it has methods to do this:

this.myCarousel.removeAll();
var items = [];
for (...) {
   items.push(<item def>);
}
this.myCarousel.add(items);
this.carousel.doLayout(); // Force the carousel to re-render
this.myCarousel.scrollToCard(0); // This will send the user back to the first card

If the user was at a different card when you run the above (say, if you put this into an orientation check) then you should return them to the correct card like so:

var curIndex = this.myCarousel.items.items.indexOf(this.myCarousel.layout.activeItem);
// Now do removing and adding
this.myCarousel.scrollToCard(this.myCarousel.items.items[curIndex]);

You have to use the index as the item will be removed.

亣腦蒛氧 2024-11-22 14:16:27

id 只能用于调试。有比使用 id 更好的方法来解析组件,这可能会给您带来麻烦。

id should only be used for debugging. There are better ways to resolve a component than use id that can get you into trouble.

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