如何解决如何根据4种条件过滤一组数据?
我的数据结构如下:
[
{title: 'a',washday: 'true',cutday: 'false',colorday: 'true',deepconditionday: 'true'},{title: 'b',washday: 'false',cutday: 'true',colorday: 'false',deepconditionday: 'false'},{title: 'c',{title: 'd',]
我的应用程序中还有 cutday , colorday , deepconditionday 和 washday 的状态,一个在布尔值true和false之间切换的开关。
如何根据打开的状态过滤上述数据?例如,如果仅启用colorday,则我要显示colorday为“ true”的所有项目。如果将deepconditionday和cutday都打开,那么我要显示出cutday和deepconditionday均为“ true”的所有项目。
谢谢。
解决方法
可能是这样的:
let titleFilter = "a";
let washdayFilter = true;
let cutdayFilter = true;
let filteredData = data.filter(
(datapoint) =>
datapoint.title == titleFilter &&
datapoint.washday == washdayFilter.toString() &&
datapoint.cutday == cutdayFilter.toString()
);
,
static func registerSubscriptionWith(ID: String) {
let predicate = NSPredicate(format: "channelID == %@",ID)
let subscription = CKQuerySubscription(recordType: "Episode",predicate: predicate,options: .firesOnRecordCreation)
let myContainer = CKContainer.default()
let publicDatabase = myContainer.publicCloudDatabase
let recordID = CKRecord.ID(recordName: ID)
publicDatabase.fetch(withRecordID: recordID) { (record,error) in
if let error = error {
print("Error: \(error.localizedDescription)")
} else {
if record != nil {
let notification = CKSubscription.NotificationInfo()
notification.title = record!["channelName"]
notification.alertBody = record!["caption"]
notification.soundName = "default"
subscription.notificationInfo = notification
publicDatabase.save(subscription) { result,error in
if error != nil {
print(error!.localizedDescription)
} else {
print("Success subscribing user to episode notifications")
}
}
}
}
}
}
更多信息在这里: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
请注意,您使用'true'和'false'作为字符串,而不是布尔值,因此我也这样做。 您应该使用布尔值并相应地更改代码 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
,我已经实现了使用ReactJS和MaterialUI的示例。只需将状态用于开关并按状态过滤即可。链接演示:https://codesandbox.io/s/material-demo-forked-176e3?file=/demo.js
awk 'match($0,/{[^\\]*/){print substr($0,RSTART+1,RLENGTH-1)}' Input_file
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。