XPage [TypeError] view.getNextDocument(curDoc) 异常 [英] XPages [TypeError] Exception at view.getNextDocument(curDoc)

查看:22
本文介绍了XPage [TypeError] view.getNextDocument(curDoc) 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:

在我的 XPage 中,我有一个嵌入式视图,它可以在相邻的面板中打开一个文档.单击视图中的文档链接会在 viewScope 变量中设置文档的 UNID,并刷新面板.UNID 变量用于定义页面的数据源文档(doc).

In my XPage, I have an embedded view which opens a document in the adjacent Panel. Clicking the doc link in the view sets the doc's UNID in a viewScope variable, and refreshes the Panel. The UNID variable is used to define the Page's Data Source Document (doc).

现在在一个按钮中,我想获取视图中下一个文档的句柄,但是当运行以下 SSJS 代码时,最后一行出现错误:

Now in a Button, I want to get a handle to the next document in the view, but when the following SSJS code is run an error occurs at the last line:

var v:NotesView = database.getView("ViewByYear");
var curDoc:NotesDocument = doc.getDocument();
// curDoc = v.getFirstDocument(); /* if this line is uncommented the error does not occur */

if (curDoc==null) return(false);
var nextDoc = v.getNextDocument(curDoc);

错误信息为:Script interpreter error, line=11, col=32: [TypeError] 调用方法 NotesView.getNextDocument(lotus.domino.local.Document) null 时发生异常

如果我取消注释注释行(将 curDoc 设置为视图中的第一个文档),则不会发生错误.

if I uncomment the commented line (setting curDoc as the first document in the view), the error does not occur.

知道为什么会这样吗?从数据源生成的文档有何不同?无论如何,该文档来自嵌入在同一个 XPage 中的同一个视图.

Any idea why this is happening? How is the document generated from the Data Source different? This document comes anyway from this same view which is embedded on the same XPage.

感谢您的见解

推荐答案

实际上,这完全符合预期 :-)

Actually, this works exactly as expected :-)

它与变量类型等无关.基本上,如果你想遍历一个视图,你需要设置起始"点,在你的情况下,你使用 curDoc = v.getFirstDocument();.然后,当您想要下一个文档时,您可以使用 nextDoc = v.getNextDocument(curDoc);,即您告诉它返回位于 curDoc 之后的文档.这是自从 LotusScript 在第 4 版中引入以来后端对象的工作方式.无论您使用 LotusScript、SSJS 还是 Java,它都是相同的模式:-)

It has nothing to do with type of variables etc. Basically, if you want to traverse a view you need to set the "starting" point which in your case you do with curDoc = v.getFirstDocument();. Then when you want the next document you use nextDoc = v.getNextDocument(curDoc);, i.e. you tell it to return the document following the curDoc. This is the way the backend objects have been working since LotusScript was introduced back in version 4. And it is the same pattern no matter whether you use LotusScript, SSJS or Java :-)

所以一个常见的模式是:

So a common pattern would be:

var v:NotesView = database.getView("ViewByYear");
var curDoc = v.getFirstDocument();
while(null != curDoc){
  // Do some work with curDoc
  curDoc = v.getNextDocument(curDoc);
}

现在,您可能听说过与遍历视图有关的内存注意事项.基本上,Domino 通常会为您处理内存.但尤其是在迭代大型文档集合时,您应该使用稍微不同的模式(您也可以将其用于小型文档集合):

Now, you may have heard of memory considerations in relation to traversing a view. Basically, Domino will normally take care of memory handling for you. But especially when iterating over large document collections you should use a slightly different pattern (which you can also use for small document collections):

var v:NotesView = database.getView("ViewByYear");
var curDoc = v.getFirstDocument();
var nextDoc = null;
while(null != curDoc){
  nextDoc = v.getNextDocument(curDoc);
  // Do some work with curDoc
  curDoc = null; // reclaim memory
  curDoc = nextDoc;
}

/约翰

这篇关于XPage [TypeError] view.getNextDocument(curDoc) 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆