我通过SSJS编写了如下代码。当我休息时,我想结束while循环功能(我写过//做工作人员......我想去哪里)。 我的问题是我必须使用哪些代码?
while (docOrg!= null)
{
var tmpdoc = viewOrg.getNextDocument();
if (docOrg.getItemValueString("Name")== docSta.getItemValueString("CompanyName"))
{
FIRM_ID = docOrg.getItemValueString("VAT");
FIRM_NAME= docOrg.getItemValueString("InvoiceName");
FIRM_ADDRESS=docOrg.getItemValueString("InvoiceAddress");
FIRM_REGION=docOrg.getItemValueString("CompanyRegion") ;
break;
}
docOrg.recycle();
docOrg = tmpdoc;
}
//do staff...
答案 0 :(得分:4)
中断应该按预期工作。它跳到“//做员工”。虽然...
......可能有更好的方法。您浏览视图以查找此公司文档。如果您使用视图索引查找公司的文档,性能会好得多:
var viewCompanies = db.getView("Companies");
var docOrg = viewCompanies.getDocumentByKey(docSta.getItemValueString("CompanyName", true));
if (docOrg!= null) {
FIRM_ID = docOrg.getItemValueString("VAT");
FIRM_NAME= docOrg.getItemValueString("InvoiceName");
FIRM_ADDRESS=docOrg.getItemValueString("InvoiceAddress");
FIRM_REGION=docOrg.getItemValueString("CompanyRegion") ;
docOrg.recycle();
}
答案 1 :(得分:2)
我同意您的代码应按预期中断。但是,我会稍微改变它以完成循环 - 就像这样:
while (docOrg!= null)
{
var tmpdoc = viewOrg.getNextDocument();
if (docOrg.getItemValueString("Name")== docSta.getItemValueString("CompanyName"))
{
FIRM_ID = docOrg.getItemValueString("VAT");
FIRM_NAME= docOrg.getItemValueString("InvoiceName");
FIRM_ADDRESS=docOrg.getItemValueString("InvoiceAddress");
FIRM_REGION=docOrg.getItemValueString("CompanyRegion") ;
// break;
tmpdoc = null; // This will ensure cleanup of docOrg - and stop loop :-)
}
docOrg.recycle();
docOrg = tmpdoc;
}
/约翰