【问题标题】:Magnolia, JCR, sort node order by customized property valueMagnolia,JCR,按自定义属性值排序节点顺序
【发布时间】:2017-07-31 16:33:07
【问题描述】:

例如,我有一个节点 ref 29949,它具有如下属性:

所以它的 positionIndex 是 1,这是一个自定义属性。 我当前的节点是完全无序的,像这样:

我希望通过这个property-positionIndex来比较节点并将其排序为升序,所以这个节点29949将位于44440之下,因为44440的值为positionIndex 0。有人知道怎么做吗?任何代码示例都会很好。
干杯

【问题讨论】:

    标签: java sorting aem jcr magnolia


    【解决方案1】:

    首先,你应该为自己抢一个会话(也可以注入)

    Context context = MgnlContext.getInstance();
    Session session = context.getJcrSession("choiceOfWorkspace");
    
    // Must be the parent of the nodes to be compared.
    
    Node rootNode = session.getRootNode();
    NodeIterator iterator = rootNode.getNodes();
    
    // just do an iteration over the iterator
    
    while(iterator.hasNext()){
    Node nextNode = iterator.nextNode();
    property = nextNode.getProperty("positionIndex");
    // do any sorting algorithm here
    }
    

    希望对你有帮助

    干杯,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多