如何使用CloudKit.js查询nil值? [英] How do I query for nil values with CloudKit.js?

查看:122
本文介绍了如何使用CloudKit.js查询nil值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CloudKit.js,如何构建与字段为零的项目匹配的查询?我尝试的每个排列都会失败-要么明显匹配字符串值(即"null"或"nil"),要么如果我实际尝试传递"null",则会引发错误.

Using CloudKit.js, how do I construct a query that matches items where a field is nil? Every permutation I've tried fails - either it's clearly matching on a string value (i.e. "null" or "nil") or it throws an error if I actually try to pass 'null'.

有什么想法吗?以下都不起作用.

Any ideas? None of the below work.

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "nil" }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: null }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "null" }
}]

filterBy: [{
        fieldName: 'customerNumber',
        comparator: 'EQUALS',
        fieldValue: { value: "" }
}]

推荐答案

我认为CloudKit中没有任何查询nil值的选项.同样不是来自本机代码.我尝试了很多谓词,但似乎没有用.

I don't think there is any option to query for nil values in CloudKit. Also not from native code. I have tried a lot of predicates, but non seems to work.

您必须知道CloudKit是键值存储.当值为nil时,键将不在记录中.没有选项来查询不存在的密钥.

You do have to be aware that CloudKit is a key-value store. When a value is nil, then the key won't be there in the record. There is no option to query for non existing keys.

最接近我找到一个好的解决方案的是谓词,其格式为"NOT myField => ''"抱歉,不知道.js的格式

The closest I have come to a good solution was with a predicate with the format "NOT myField => ''" sorry, don't know the format for .js

CloudKit CKQuery文档中,没有提到零字段.

In the CloudKit CKQuery documentation there is nothing mentioned about nil fields.

NSPredicates的文档中有零个值的样本.

但是已经很清楚,CloudKit仅实现了NSPredicate可能性的一部分(请参阅CKQuery类参考)

But it was already clear that CloudKit has implemented only a subset of the possibilities of NSPredicate (see CKQuery class reference)

我认为处理此问题的最佳方法是不使用/不依赖于nil值.如果确实需要检查一些零状态,则可以添加一个额外的字段来表示该状态.

I think the best way to handle this is by not using/depending on nil values. If you do need to check some nil status, then instead you could add an extra field that would represent that status.

这篇关于如何使用CloudKit.js查询nil值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆