سؤال

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]

هل كانت مفيدة؟

المحلول

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));
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top