【问题标题】:How to use substringof in azure-mobile-apps-js-client如何在 azure-mobile-apps-js-client 中使用 substringof
【发布时间】:2017-04-25 20:38:57
【问题描述】:

我想使用 azure-mobile-apps-js-client 的 odata substringof 方法。 目前我使用 indexof 方法,但想切换到 substringof。

我有这个代码

function queryFunction(term){
     return this.FullName.indexOf(term) != -1
}
table.where(queryFunction, term)

翻译成

$filter=indexof(FullName, term) ne -1

我需要这样的网址:

filter=substringof(term, FullName) eq true

我如何用 javascript 做到这一点?

【问题讨论】:

    标签: javascript node.js azure odata azure-mobile-services


    【解决方案1】:

    azure-query-js 支持一组有限的 Javascript 函数,这些函数被转换为它们的 odata 等效项。目前,没有可以映射到substringof 的函数。您使用 indexOf 的原始实现是使用 Javascript 样式查询查询子字符串的最佳选择。

    但是,如果您希望完全控制自己的查询,可以直接将 OData 查询字符串传递给 read 方法。 https://github.com/Azure/azure-mobile-apps-js-client/blob/2b5e083d400a089cb1759d6d58d96e4d10ba2310/sdk/test/tests/shared/mobileServiceTables.js#L98 就是一个例子。如果您在文件中搜索'$filter',您会发现更多示例。

    【讨论】:

    • 另外,请注意 OData 查询字符串应该是 URL 编码的。要获取 'abc + def' 是文本列的子字符串的记录,您需要执行以下操作:table.read("$filter=substringof(%27abc%20%2B%20def%27,%20text)%20eq%20true")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2017-07-24
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多