Select 来自 Adobe Livecycle ES4 中数据节点的不同元素
Select distinct element from a dataNode in Adobe Livecycle ES4
我有这个原创方法
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)
我正在尝试 select 原始方法的这一部分中唯一且不同的元素:
/*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
所以我考虑实现一个简单的解决方案是使用 twp 嵌套循环,使用受 here
启发的逻辑
// 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
我没有遇到任何错误,但是列表 returned 是空的,有人可以帮助我吗?如何 return 仅与 frmStock
不同的元素?
我最终找到了
我添加了一个功能
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);
我有这个原创方法
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)
我正在尝试 select 原始方法的这一部分中唯一且不同的元素:
/*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
所以我考虑实现一个简单的解决方案是使用 twp 嵌套循环,使用受 here
启发的逻辑// 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
我没有遇到任何错误,但是列表 returned 是空的,有人可以帮助我吗?如何 return 仅与 frmStock
不同的元素?
我最终找到了
我添加了一个功能
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);