如何在Sheetrock中使用LIKE运算符

How to use LIKE operator in Sheetrock

本文关键字:LIKE 运算符 Sheetrock      更新时间:2023-09-26

我正在尝试在SQL语句中调用LIKE之后的Javascript变量elem,以便在那里使用输入文本。但是,我这样做的方式不适用于我正在使用的 Sheetrock 库 (http://chriszarate.github.io/sheetrock/)。

<!DOCTYPE html>
<html>
<body>
Enter Tracking Code: <input type="text" id="textbox_id">
<input type="button" value="Submit">
<table id="switch-hitters" class="table table-condensed table-striped"></table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.0.1/dist/sheetrock.min.js"></script>

<script>
var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
var elem =  document.getElementById('textbox_id').value;
$('#switch-hitters').sheetrock({
    url: mySpreadsheet,
    query: "select A,B,C,D,E where A LIKE %"+elem+"%"
});
</script>
</body>
</html>

自从您更新了您的问题以来,这里是更新的答案。检查工作:https://jsfiddle.net/r0sk7vtf/

  • 您需要处理提交按钮点击事件,然后调用服务

  • 虽然电子表格 API 可以理解没有引号,但它无法通过 Sheetrock 工作.js ,因此您需要在查询中使用A like '9999%'

片段:

var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
var button = $('#btn'), elem = $('#textbox_id')
button.on('click', function(e){ 
  var v =  elem.val();
  $('#switch-hitters').sheetrock({
    url: mySpreadsheet,
    query: "select A,B,C,D,E where A like '" + v + "%'"
  });
 })