问题描述
数据库搜索代码工作正常。你可以在下面看到它。我想添加一个复选框组(5 个单元),它将与我的搜索代码集成。全部运行在一个数据库上。
我如何添加以数据库搜索代码为例的复选框组代码?
Column name
Detail ---------- Search input keyword
(the search code works but no filters).....
continent - checkboxgroup1.....
country - checkboxgroup2.....
sector - checkboxgroup3.......
fund - checkboxgroup4......
cvp code - checkboxgroup5
我的搜索代码
import wixData from 'wix-data';
export function searchButton_onClick(event)
{
//assume the input comes from a component called 'searchInput'
//CHANGE TO YOUR SPECIFIC COMPONENT NAME
let searchValue = $w('#SearchBox').value;
//split the search inputs into distinct words
let searchWords = searchValue.split(' ');
//build a query for 'my-collection'
//CHANGE THIS TO YOUR COLLECTION NAME
let query = wixData.query('Afghanistan')
.descending("overview");
//add a "contains" condition to the query for each word:
//assumes we search in the field 'myField'
//CHANGE THIS TO YOUR FIELD NAME
for (let i=0; i < searchWords.length; i++)
{
query = query.contains('overview',searchWords[i])
}
//actually run the query:
query.find().then(res =>
{
//give the results to the table to display
//assume the table is named 'resultsTable'
//CHANGE TO YOUR SPECIFIC COMPONENT NAME
$w('#repeater1').data = res.items;
})
.catch(err =>
{
console.log("problem in search! " + err);
});
}
import wixData from 'wix-data';
export function searchButton_onClick(event)
{
//assume the input comes from a component called 'searchInput'
//CHANGE TO YOUR SPECIFIC COMPONENT NAME
let searchValue = $w('#SearchBox').value;
//split the search inputs into distinct words
let searchWords = searchValue.split(' ');
//build a query for 'my-collection'
//CHANGE THIS TO YOUR COLLECTION NAME
let query = wixData.query('Afghanistan')
.descending("overview");
//add a "contains" condition to the query for each word:
//assumes we search in the field 'myField'
//CHANGE THIS TO YOUR FIELD NAME
for (let i=0; i < searchWords.length; i++)
{
query = query.contains('overview',searchWords[i])
}
//actually run the query:
query.find().then(res =>
{
//give the results to the table to display
//assume the table is named 'resultsTable'
//CHANGE TO YOUR SPECIFIC COMPONENT NAME
$w('#repeater1').data = res.items;
})
.catch(err =>
{
console.log("problem in search! " + err);
});
}
下面是过滤的工作代码。如何组合两个代码。
$w.onReady(function () {
filterView();
$w("#checkboxGroup1").onChange( (event,$w) => {
filterView();
});
$w("#checkboxGroup2").onChange( (event,$w) => {
//filterView();
//});
});
function filterView(){
var continentsFilter = $w("#checkboxGroup1").value
var countryFilter = $w("#checkboxGroup2").value
console.log('continents',continentsFilter);
console.log('country',countryFilter);
$w("#dataset1").setFilter( wixData.filter()
.hasSome("continents",continentsFilter)
.hasSome("country",countryFilter)
)
.then( () => {
let count = $w("#dataset1").getTotalCount();
if(count === 0){
$w("#group1").show();
}else{
$w("#group1").hide();
}
} )
.catch( (err) => {
console.log(err);
} );
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)