我有两个数组,第一个包含所有订单,第二个包含我从数据库中获得的拒绝订单
我需要过滤这些订单并根据快照密钥从中删除所有拒绝的订单
所以在运行我的代码之后
尽管我在控制台中测试了我的代码,但我看到了所有订单并包含了被拒绝的命令,它可以正常工作,但在我的React App中不起作用
订单数组
this.setState({
orders: orderArr.filter(
order => !rejectedOrders.some(key => order.snapshotKey === key),
),
loading: false,
});
为了使代码简短,我将进行过滤
获得订单并将其推送到单独的数组后,我将状态设置为
Const {rejectedOrders}= this.state;
database()
.ref(
`Providers/CategoriesOrders/${service ||
serviceStorage ||
serviceName}/${uid}`,
)
.on('value', snapshot => {
console.log(snapshot.val());
let orderArr = [];
snapshot.forEach(childSnapshot => {
orderArr.push({
snapshotKey: childSnapshot.key,
username: childSnapshot.val().username,
buildingNumber: childSnapshot.val().buildingNumber,
service: childSnapshot.val().categoryName,
date: childSnapshot.val().date,
time: childSnapshot.val().time,
description: childSnapshot.val().problemDescription,
status: childSnapshot.val().status,
images: childSnapshot.val().Images,
});
});
this.setState({
orders: orderArr.filter(
order => !rejectedOrders.some(key => order.snapshotKey === key),
),
loading: false,
});
});
但是可惜我得到了三个订单,没有任何过滤!
编辑1
foreach (var ownerToProcess in activeOwnersWithMessageArchiving)
{
foreach (var extension in extensions)
{
using (var db = new SqlConnection(connectionString))
{
db.Execute(@"
UPDATE T_MESSAGESTARTER
SET Started=@started,Completed=NULL
WHERE OwnerId=@ownerId AND ExtensionId=@extensionId;
if @@ROWCOUNT=0
INSERT INTO T_MESSAGESTARTER (OwnerId,ExtensionId,Started)
VALUES (@ownerId,@extensionId,@started)
", new { ownerId = ownerToProcess, extensionId = extension, started = DateTimeOffset.Now });
}
}
}