【问题标题】:Xpages: How to get only the first record of a categorised viewXpages:如何仅获取分类视图的第一条记录
【发布时间】:2020-06-19 03:39:53
【问题描述】:

我正在执行一个 while 循环来获取分类视图中的记录。 我只想返回满足 if 条件的第一条记录,而不是整个类别。 下面的代码返回类别中通过'if'条件的所有记录。

var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
while(doc != null){ 
  if(doc.getItemValueString("Status") == 'Live'){
      //get the first in the category here where condition is met
      var pVersion = doc.getItemValueString("Version");
      var pPro = doc.getItemValueString("Pro");
  }
  var tmpDoc:NotesDocument = vView.getNextDocument(doc);
  doc.recycle();
  doc = tmpDoc;
}

在下面查看:

箭头显示我想要返回的记录。

【问题讨论】:

  • 我认为您的代码非常无效。相应地计划。根据您的条件创建一个包含类别的视图。然后使用 NotesViewNavigator,只遍历类别,得到每个类别的第一个文档。

标签: xpages lotus-notes lotus-domino xpages-ssjs domino-designer-eclipse


【解决方案1】:

您的图形表明您想要每个类别中满足条件的第一个文档?

对于所提出的问题:

var continueSearch = true
 while(doc != null && continueSearch) {
       if(...) {
            ...
            continueSearch = false;
        }
   ...
    }

应该这样做

【讨论】:

    【解决方案2】:

    找到文档后尝试跳出循环:

    var vView:NotesView = database.getView("Document");
    var doc:NotesDocument = vView.getFirstDocument();
    var done = false;
    while(doc != null && !done){ 
      if(doc.getItemValueString("Status") == 'Live'){
          //get the first in the category here where condition is met
          var pVersion = doc.getItemValueString("Version");
          var pPro = doc.getItemValueString("Pro");
          done = true;
      }
      var tmpDoc:NotesDocument = vView.getNextDocument(doc);
      doc.recycle();
      doc = tmpDoc;
    }
    

    【讨论】:

    • 如果是在退出循环时保留 doc 的想法,我建议仅在 done 为 false 时执行最后三个命令。
    【解决方案3】:

    你看过 notesviewnavigator 类吗?

    【讨论】:

      【解决方案4】:
             var vView:NotesView = database.getView("Document");
             var doc:NotesDocument = vView.getFirstDocument();
             var product;
             while(doc != null){
                  if(product != doc.getItemValueString("Product")){
                    //get only the first in the category
                    var pVersion = doc.getItemValueString("Version");
                    var product = doc.getItemValueString("Product");
                  }
             var tmpDoc:NotesDocument = vView.getNextDocument(doc);
             doc.recycle();
             doc = tmpDoc;
             }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-14
        • 2014-11-08
        • 1970-01-01
        • 1970-01-01
        • 2019-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多