MarkLogic:fn.empty fn.exsits!== null!==“”

问题描述 投票:1回答:1

下面的语句之间的最终区别是什么,以确定cts.search是否返回有效的文档?

1. if (!fn.empty(acctDoc)) {....}
    2. if (!fn.exists(acctDoc)) {....}
    3. if (acctDoc !== null || acctDoc !== "") {...}

我的经验是,No.3在各个方面都有效。

conditional-statements marklogic
1个回答
0
投票
    if (!fn.empty(acctDoc)) {....}如果acctDoc
  1. 不是空序列,则返回true。
  2. [if (!fn.exists(acctDoc)) {....}如果acctDoc
  3. 是空序列,则返回true。
  4. [if (acctDoc !== null || acctDoc !== "") {...}如果acctDoc不是null或它不是一个空字符串,则返回true。
  • fn.empty()

    如果$ arg的值为空序列,则该函数返回true;否则,该函数返回true。否则,该函数返回false。

    fn.exists()

    如果$ arg的值不是空序列,则该函数返回true;否则,该函数返回true。否则,该函数返回false。

    使用此测试功能:

    function test(acctDoc) { const results = []; if (!fn.empty(acctDoc)) { results.push("not empty") }; if (!fn.exists(acctDoc)) { results.push("does not exist") }; if (acctDoc !== null || acctDoc !== "") { results.push("not null or is not empty string") }; return results;

    }

      [test("test")返回["not empty", "not null or is not empty string"]
  • [test("")返回["not empty", "not null or is not empty string"]
  • [test(null)返回["does not exist", "not null or is not empty string"]
  • [test(fn.head(fn.doc()))返回["not empty", "not null or is not empty string"]
  • [test(fn.doc(fn.string(xdmp.random())))返回["does not exist", "not null or is not empty string"]
  • © www.soinside.com 2019 - 2024. All rights reserved.