我有这个原始方法
var firstLine = ""
if( frmStock.txtPRSID.rawValue <> null or frmStock.txtPRSDesp.rawValue <> null )
then
firstLine = Concat(frmStock.txtPRSID.formattedValue," ",frmStock.txtPRSDesp.formattedValue)
endif
var secondLine = ""
if( frmStock.frmSN.txtSN.rawValue <> null )
then
var snData = ref(frmStock.frmSN.txtSN.dataNode.parent)
var snSet = ref(snData.resolveNodes("$.MaterialSerialID[*]"))
var temp = ""
for i=0 upto snSet.length-1
do
var Content = ref(snSet.item(i).resolveNode("$"))
if( Content <> null )
then
temp = Concat(temp,Content.value)
if( i <> snSet.length - 1 )
then
temp = Concat(temp,"\u000a")
endif
endif
endfor
secondLine = temp
endif
if( secondLine == "" )
then
secondLine = Concat(frmStock.txtType.formattedValue," ",frmStock.txtID.formattedValue)
endif
this.rawValue = Concat(firstLine,"\u000a",secondLine)
我试图从原始方法的这一部分中选择唯一且独特的元素:
/*This returns stuff like P0001 , P3333, P0001 , P444, P3333 */
var snData = ref(frmStock.frmSN.txtSN.dataNode.parent)
var snSet = ref(snData.resolveNodes("$.MaterialSerialID[*]"))
var temp = ""
for i=0 upto snSet.length-1
do
var Content = ref(snSet.item(i).resolveNode("$"))
if( Content <> null )
then
temp = Concat(temp,Content.value)
if( i <> snSet.length - 1 )
then
temp = Concat(temp,"\u000a")
endif
endif
endfor
因此,我想实现一个简单的解决方案是使用受here
启发的逻辑使用twp嵌套循环// Pick all elements one by one
for (int i = 0; i < list.lengh; i++)
{
// Check
int j;
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
skip
// If not add it to list
if (i == j)
add to list
}
所以我尝试将逻辑应用于方法
var snData = ref(frmStock.frmSN.txtSN.dataNode.parent)
var snSet = ref(snData.resolveNodes("$.MaterialSerialID[*]"))
var temp = ""
for i=0 upto snSet.length-1
do
for j=0 upto i-1
do
var tempI= ref(snSet.item(i).resolveNode("$"))
var tempJ= ref(snSet.item(j).resolveNode("$"))
if(tempI <> tempJ)
then
break
if(i==j) then
var Content = ref(snSet.item(i).resolveNode("$"))
if( Content <> null )
then
temp = Concat(temp,Content.value)
if( i <> snSet.length - 1 )
then
temp = Concat(temp,"\u000a")
endif
endif
endif
endif
endfor
endfor
我没有遇到任何错误,但返回的列表为空,有人可以帮助我吗?如何仅返回frmStock
中不同的元素?
答案 0 :(得分:0)
我最终发现了
我添加了一个功能
function uniq(a) {
return a.sort().filter(function(item, pos, ary) {
return !pos || item != ary[pos - 1];
})
}
然后将其应用于项目的数据源
var data = snData.resolveNodes("$.MaterialSerialID[*]");
var uniqData = uniq(data);