【发布时间】:2022-01-19 21:32:29
【问题描述】:
我正在 Wix 上创建一个页面,其中我有一个中继器,当单击应该洗牌并带来不同组合的洗牌按钮(数据集中有 22 张牌)时,它一次只能从我的数据集中带来 3 个项目.
我的期望: 点击按钮,然后它会从一副 22 张卡片中随机抽取 3 张卡片(即我数据集中卡片的图像)。
发生了什么: 它带来了相同的几种卡片组合,实际上并不是随机的,有些卡片永远不会出现。
这是我的代码:
export function button7_click(event) {
// clear any filters in the dataset
$w("#dynamicDataset").setFilter( wixData.filter() );
// get size of collection that is connected to the dataset
let count = $w("#dynamicDataset").getTotalCount();
// get random number using the size as the maximum
let idx = Math.floor(Math.random() * count-1);
// set the current item index of the dataset
$w("#dynamicDataset").setCurrentItemIndex(idx);
}
我该怎么做才能带来真正随机散布的 3 张牌?
【问题讨论】:
标签: javascript shuffle velo