Xpages - 在重复控件中显示已过滤的文档集合

时间:2012-11-22 14:38:29

标签: javascript xpages

我在重复控件的Bind数据部分中有以下代码。我把Collection Name称为'docs'。我似乎无法使任何值出现在视图控件中。计算字段 - docs.getItemValue(“状态”)。我出错的任何想法?

var v:NotesView = database.getView("xpageReports");
viewScope.status=""

// Created After
var after = viewScope.crafter
if(after==null)after = @Date(2000, 1, 1, 0, 0, 0);  

// Created Before
var before = viewScope.crbefore 
if(before==null) before = @Date( @Tomorrow() );

// Build Date Range
var dr = session.createDateRange(after, before);

// Status
var status = viewScope.crstatus;
if(status =="-select-") status =""
// Department
var department = viewScope.crdepartment;
if(department =="-select-") department=""

// Unit
var unit = viewScope.crunit;
if(unit ="-select-") unit=""

var dc:NotesDocumentCollection = v.getAllDocumentsByKey(dr);
if (dc.getCount() == 0) {
    viewScope.status = "0";
    return;
}

var count = 0
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
    var tmpdoc = dc.getNextDocument();
    var remove = 0

    @If(status!="",@If(doc.getItemValueString("Status")!=status,remove = remove + 1,""),"")
    @If(department!="",@If(doc.getItemValueString("Department")!=department,remove = remove + 1,""),"")
    @If(unit!="",@If(doc.getItemValueString("Unit")!=unit,remove = remove + 1,""),"")
    if(remove!=0) dc.deleteDocument(doc)

    doc.recycle();


    doc = tmpdoc;

    }

return dc

2 个答案:

答案 0 :(得分:1)

我更改了代码以返回文档的noteID,并将其放在repeat控件的Bind Data部分中,并将Collection Name设置为 docs

var v:NotesView = database.getView("xpageReports");
var docIDs = ""

// Created After
var after = viewScope.crafter
if(after==null)after = @Date(2000, 1, 1, 0, 0, 0);  

// Created Before
var before = viewScope.crbefore 
if(before==null) before = @Date( @Tomorrow() );

// Build Date Range
var dr = session.createDateRange(after, before);

// Status
var status = viewScope.crstatus;
if(status =="-select-") status =""
// Department
var department = viewScope.crdepartment;
if(department =="-select-") department=""

// Unit
var unit = viewScope.crunit;
if(unit =="-select-") unit=""

var dc:NotesDocumentCollection = v.getAllDocumentsByKey(dr);
if (dc.getCount() == 0) {
    return;
}

var count = 0
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
    var tmpdoc = dc.getNextDocument();
    var remove = 0

    @If(status!="",@If(doc.getItemValueString("Status")!=status,remove = remove + 1,""),"")
    @If(department!="",@If(doc.getItemValueString("Department")!=department,remove = remove + 1,""),"")
    @If(unit!="",@If(doc.getItemValueString("Unit")!=unit,remove = remove + 1,""),"")
    if(remove==0) docIDs = docIDs = docIDs + doc.getNoteID()+";"

    doc.recycle();
    doc = tmpdoc;

}
return @Explode(docIDs,";")

然后我在重复控件中放置了一个面板,将数据源设置为文档的形式,并将Document ID字段设置为computed并输入 docs 。现在我放在面板中的任何计算字段都可以绑定到表单字段

答案 1 :(得分:0)

据我了解您的问题,您希望在重复控件中显示视图中的文档子集 - 您的过滤应按日期范围完成。 我通过使用以下逻辑完成了类似的事情:

  1. 我的自定义控件/ xpage的数据源是一个视图(在您的情况下是视图“xpageReports”),数据源名称=“view1”。
  2. 在数据源属性中,您有三个缩小文档集范围的选项:“按类别名称过滤”,“按列值过滤”和“在视图结果中搜索”。在我的情况下,我使用“在视图结果中搜索”(在具有全文索引的数据库中)。 因此,您可以使用JavaScript创建如下查询:
  3. '[dateAfter]>=01.01.2000 AND [dateAfter]<=31.12.2012';

    1. 在重复中,您可以将来源设置为“view1”

    2. 集合名称可以设置为“mydoc”

    3. 可以使用代码访问重复内的计算字段中的列值

    4. mydoc.getColumnValue("PROGRAMMATICCOLUMNNAME");

      我希望这是对正确方向的暗示。据我了解,应符合您的要求。