relaymodern - 中继现代商店客户端中的排序连接
问题描述
我有一个突变,可以重新排序中继连接中的两条边。乐观地执行这种重新排序的正确方法是什么?我尝试了一种就地排序,例如:
const conn = ConnectionHandler.getConnection(pathway, 'PathwayGraph_actions');
const edges = conn.getLinkedRecords('edges');
edges.sort((a, b) => {
const laneA = a.getLinkedRecord('node').getValue('laneNumber');
const laneB = b.getLinkedRecord('node').getValue('laneNumber');
return laneA - laneB;
});
这似乎不起作用。我怀疑中继非常努力地不允许存储突变,除非通过其界面。我想我可以使用 ConnectionHandler 删除所有现有的边缘,然后以正确的顺序将它们全部添加回来,但这听起来很麻烦。有没有更好的办法?
解决方案
RecordProxy.setLinkedRecords使这不那么糟糕:
edges.sort((a, b) => {
const laneA = a.getLinkedRecord('node').getValue('laneNumber');
const laneB = b.getLinkedRecord('node').getValue('laneNumber');
return laneA - laneB;
});
conn.setLinkedRecords(edges, 'edges');
如果有人有更时尚的方式,仍然有点好奇。
推荐阅读
- bash - 如果没有找到正向搜索结果,如何重置光标处的行?
- r - 更改数据框中的变量类型
- django - ImportError:来自 django.urls 的导入路径不起作用
- python - 无法在 Python 和 telnetlib 中的自定义 Preamble 之间解压信息
- javascript - 如果光标已经在元素上,则在页面加载时触发鼠标输入事件
- sql - SQL将未知级别添加到层次结构
- javascript - dc.js 折线图未显示任何内容
- json - 从 react.js 中的本地 .json 文件获取数据返回多个错误
- c# - 将抛出的异常从扩展方法传递给C#中的调用函数
- python-3.x - 如何将python脚本放入AWS?