xpages:比较两个视图之间的值 [英] xpages : compare values between two views
问题描述
我打算比较两个视图之间的值.
I intend to compare values between two views.
想象一下 view1 有以下值:
Imagine view1 has the following values:
Location | Officer
Australia| Peter
Beglium | John
Chile | Ben
Italy | Mike
想象一下 view2 有以下值:
Imagine view2 has the following values:
Item | Location
Book | Italy
Journal | Australia
Movie | Spain
我想做的是比较 view1 和 view2 之间的值.
What I would like to do is compare values between view1 and view2.
我写了以下代码:
var location = sessionScope.Location;
var message = "";
var view1 = @DbLookup(@DbName(), "view1", location , 0)); // use session scope variable to lookup in view1 and find location
var view2 = @DbLookup(@DbName(), "view2", view1 , 1)); // use view1 value to lookup in view
for(var x = 0; x < view1.length; x++)
{
for(var y = 0; y < view2.length; y++)
{
if(view1[x] == view2[y])//if value exist in view1 and view2
{
message = "value matches";
}
else // if not match
{
message = "value does not match";
}
// show the result in the excel
//first row list all values in view1 and the second row will show the message
writer.write("<tr><td>" + view1[x] + "</td></tr>" + message + "</td></tr>");
}
}
当我运行程序时,我看到 view1[x] 工作正常,因为它可以在 view1 中显示值,但是关于显示消息,它只显示值不匹配",即使值存在于 view1 和 view2 中.
When I run the program, I see view1[x] works fine as it can show values in view1, however about display the message, it only shows "value does not match" even the value exists in view1 and view2.
结果如下:
Australia | value does not match
Beglium | value does not match
Chile | value does not match
Italy | value does not match
我想知道为什么消息只显示 else 部分,而不知道为什么它没有为 view1[x] 中的每个值显示正确的消息.
I would wonder to know why the message only display the else part and not sure why it does not show the proper message for each value in view1[x].
实际上我想结果是这样的:
Actually I suppose the result will look this:
Australia | value matches
Beglium | value does not match
Chile | value does not match
Italy | value matches
代码中的错误是什么?感谢您的建议.谢谢.
What is the mistake in the code? Grateful for your advice please. Thank you.
推荐答案
将您的代码更改为
for(var x = 0; x < view1.length; x++) {
message = "value does not match";
for(var y = 0; y < view2.length; y++) {
if(view1[x] == view2[y]) {
message = "value matches";
break;
}
}
// show the result in the excel
//first row list all values in view1 and the second row will show the message
writer.write("<tr><td>" + view1[x] + "</td></tr>" + message + "</td></tr>");
}
这篇关于xpages:比较两个视图之间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!