问题
I am writing a JavaScript client for an Azure Mobile Service. I am trying to use the LIKE clause (or equivalent) in the JavaScript Where clause, when I am querying a table. Does any one know how to do this? [Essentially I want to see whether a string starts with a particular value or not]
回答1:
You can use the indexOf
function, which is supported in the function:
var table = client.getTable('tableName');
var queryValue = document.getElementById('txtField').value;
table.where(function(startsWith) {
return this.name.indexOf(startsWith) === 0; // for 'contains', use >= 0
}, queryValue).read().done(function(results) {
alert('Results: ' + JSON.stringify(results));
}, function(err) {
alert('Error: ' + JSON.stringify(err));
});
来源:https://stackoverflow.com/questions/22484501/using-like-clause-in-azure-mobile-services-javascript-client