有没有办法根据用户输入动态生成 where 条件。我有一个带有选项 '>'、'<'、'equals'、'starts with'、'ends with' 的选择框。基于此条件 where 子句应该生成并且应该执行查询。请帮助我。我需要示例。因为我的表中有大约 80 列我不能使用 if else 循环。
function querymap()
{
var querypass=document.getElementById('query-pass').value.replace(/'/g, "\\'");
if(querypass=='hhSanitHouseType')
{
var operator=document.getElementById('operatorstring').value.replace(/'/g, "\\'");
if(operator=='>')
{
var textvalue=document.getElementById("text-value").value.replace(/'/g, "\\'");
layer.setQuery("SELECT 'geometry',hhSanitHouseType FROM " + tableid + " WHERE 'hhSanitHouseType' > '" + textvalue + "'");
}
}
else
{
alert("false");
}
}