【问题标题】:Sort connection in relay modern store client side中继现代商店客户端中的排序连接
【发布时间】:2020-01-07 18:40:12
【问题描述】:

我有一个突变,它对中继连接中的两条边进行重新排序。乐观地执行这种重新排序的正确方法是什么?我尝试了一种就地排序,例如:

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 删除所有现有的边缘,然后以正确的顺序将它们全部添加回来,但这听起来很麻烦。有没有更好的办法?

【问题讨论】:

    标签: relaymodern


    【解决方案1】:

    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');
    

    如果有人有更时尚的方式,还是有点好奇。

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2019-09-01
      • 1970-01-01
      • 2020-08-08
      • 2014-03-08
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多