我正在开发一个xpage应用程序,在这个应用程序中,我希望显示每个客户端总卷的top5。
我有一份购买任何数量产品的客户名单,我想根据购买的产品总量对客户进行分类。我使用按客户分类的"Top5“视图。
我使用一个文档集合来计算客户的总容量。
我可以按降序对卷进行分类,并选择前5,但这不允许我从视图中检索产品和客户端的名称。
var cls3 = @DbColumn("","Top5",1);
sessionScope.put("clientsList3",cls3);
var db=session.getCurrentDatabase();
var view7=db.getView("Top5")
var dataa =[] ;
var top =[];
for(var r = 0; r < clientsList3.length; r++){
var Cli = @Trim(@Text(clientsList3[r]));
var VolumeTotal :NotesDocumentCollection = view7.getAllDocumentsByKey(Cli);
var vola = 0;
var array = new Array();
var prod = "";
if (VolumeTotal == 0) {array = 0;}
else{
var doca = VolumeTotal.getFirstDocument();
while (doca != null)
{vola = vola + doca.getItemValueInteger("TotalVolume_Intermediate");
doca = VolumeTotal.getNextDocument(doca);
}
array.push(vola);
}
dataa[r] = array;
dataa.sort(function(a, b) {return b - a;});
top = dataa.slice(0,5);
}
return dataa;
}发布于 2014-03-17 22:51:56
您确实希望为此使用托管bean,这会使许多事情变得容易得多。创建一个自定义类,为您执行比较操作:
public Class TopSeller implements Comparable {
String product;
public String getProduct() {
return this.product;
}
public void setProduct(String product) {
this.product = product;
}
// Add properties as needed
public int compareTo(Topseller theOther) {
// Your ranking code goes here
}
}在该类中,您的compareTo函数确实提供了排序和排序。那你只需要:
Set<TopSeller> allSeller = new TreeSet<TopSeller>();..。你就完蛋了。树集将提供就绪排序结果,您只需将其绑定到要显示的5行重复。
https://stackoverflow.com/questions/22456735
复制相似问题