我可以将1个孩子减去另一个孩子的orderByChildren或orderByValue吗?(或使用计算变量的其他任何方式) [英] Can I orderByChildren or orderByValue substracting 1 child to another? (or any other mean to use a computed var)

查看:39
本文介绍了我可以将1个孩子减去另一个孩子的orderByChildren或orderByValue吗?(或使用计算变量的其他任何方式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做到这一点?还是使用oderByValue?还有其他意思吗?

Is there a way to do this ? Or with oderByValue ? Any other mean ?

fb.orderByChild('upvotes - downvotes').startAt(_start).endAt(_end).limitToLast(_n).on("child_added", function(dataSnapshot) {
          data.push(dataSnapshot.val());
       });

P.S .:是的,尽管我已经打算在数据库中创建第三个条目来跟踪(upvotes-downvotes),但这是我想避免的.

P.S.: Yes, I already though about creating a third entry in the database that keeps track of (upvotes-downvotes), but that is what I would like to avoid here.

推荐答案

不, orderByChild 确实按照其名称所说.当前,既无法在数据模型中也无法在查询条件中定义此类计算"节点.

No, orderByChild does exactly what its name says. Currently, there is no way to define such "computed" nodes neither in the data model, nor in query criteria.

因此,您应该将差异直接存储在数据库中,使用安全规则在其上设置索引,并将其用于查询.使用交易更新投票计数应该可以帮助有很多方法可以干净地实现它.

Therefore, you should store the difference directly in the database, set an index on it using security rules, and use that for your query. Updating the vote counts with a transaction should help a lot to implement it in a clean way.

这篇关于我可以将1个孩子减去另一个孩子的orderByChildren或orderByValue吗?(或使用计算变量的其他任何方式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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