fusiontable query for where

↘锁芯ラ 提交于 2019-12-12 05:05:16

问题


Is there any way to generate where condition based on user input dynamically.I have a select box with the option '>','<','equals','starts with','ends with'.Based on this condition where clause should be generated and query should be executed.Please help me.i need examples. since i have around 80 columns in my table i cant use if else loop.

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");
   }
}

回答1:


Maybe you can check this example, especially the function generateWhere(columnName, low, high).

You don't have to use if/else for your operator, just check for a valid input (i.e. that the operator is one of '>','<','equals','starts with','ends with') and then pass it directly to your query, something like that

 var operator = ...;
 var textvalue = ...;
 layer.setQuery("SELECT 'geometry',hhSanitHouseType FROM " + tableid + " WHERE 'hhSanitHouseType'" + operator + " '" + textvalue + "'");


来源:https://stackoverflow.com/questions/10083120/fusiontable-query-for-where

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!