我创建了一个带有wixcode的下拉列表(值是时间字段;从数据库中过滤DUPLICATES)并努力将时间从14:00:00.000转换/削减到14:00。 我确实在consol.log中获得了正确的值,但是不能将它们作为选择添加到我的下拉列表中。 (请参见代码)
第二个问题是: 我添加了unshift函数,将“ all”添加为附加选项,但是得到了一个空的中继器。我已经尝试将“ AND”作为值,但没有任何效果。
很高兴在这里获得有用的提示和技巧。
提前
import wixData from 'wix-data';
$w.onReady(async function () {
wixData.query("times")
.limit(1000)
.ascending("signInDay1")
.find()
.then(results => {
const uniqueItems = getUniqueItems(results.items);
$w("#dropdownTime").options = buildOptions(uniqueItems);
let cleanList = buildOptions(uniqueItems);
cleanList.unshift({ label: 'All', value: "" });
// to convert/cut the time to 4 digits (5 plus :)
for (var i = 0; i < uniqueItems.length; i++) {
var timestring = uniqueItems[i][0] + "" + uniqueItems[i][1] + "" + uniqueItems[i][2] + "" + uniqueItems[i][3] + "" + uniqueItems[i][4];
uniqueItems[i] = timestring;
console.log(timestring); //console brings the right value/RESULT, but doesnt whow up the way I want in the dropdown = 14:00:000.00 instead of 14:00
console.log(cleanList)
}
$w("#dropdownTime").options = cleanList; //buildOptions(uniqueItems);
});
function getUniqueItems(items) {
const itemsOnly = items.map(item => item.signInDay1);
return [...new Set(itemsOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr , value: curr };
});
}
});
export function dropdownTime_change(event) {
let signInDay1Value = $w("#dropdownTime").value;
$w("#dataset2").setFilter(wixData.filter().eq("signInDay1", signInDay1Value));
}
SCREENSHOT OF MY PROBLEM:
```[enter image description here][1]
[1]: https://i.stack.imgur.com/7NK9N.png