以编程方式将自定义控件中的编辑框绑定到表单域
我有一个笔记表单,其中包含一系列字段,例如 city_1、city_2、city_3 等.
I have a notes form with a series of fields such as city_1, city_2, city_3 etc.
我有一个 XPage,在那个 XPage 上我有一个重复.
I have an XPage and on that XPage I have a repeat.
重复基于具有十个值 1 - 10 的数组
The repeat is based on an array with ten values 1 - 10
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
返回(repArray);
return(repArray) ;
在重复中,我有一个自定义控件,用于显示 city_1 到 city_10 字段
Within the repeat I have a custom control which is used to surface the fields city_1 through city_10
repeat 有一个自定义属性 docdatasource 传入它还有一个名为 cityFieldName 的字符串自定义属性,它是使用重复计算的集合名称,以便在第一个重复行中为 city_1,在第二个中为 city_2 等.
The repeat has a custom property docdatasource which is passed in It also has a string custom property called cityFieldName which is computed using the repeat collection name so that in the first repeat row it is city_1 and in the second it is city_2 etc..
自定义控件上的可编辑文本字段使用EL公式绑定CompositeData.docdatasource[compositeData.cityFieldName]
The editable text field on the custom control is bound using the EL formula compositeData.docdatasource[compositeData.cityFieldName]
这很好用,但每次我添加新字段时,我都必须记住创建一个新的自定义属性,然后在父页面上引用它.
This works fine but each time I add new fields I have to remember to create a new custom property and then a reference to it on the parent page.
我希望能够简单地计算数据绑定,例如
I would like to be able to simply compute the data binding such as
compositeData.docdatasource['city_' + indexvar]
其中 indexvar 是表示当前行号的变量.
where indexvar is a variable representing the current row number.
这可能吗?我读到您不能在表达式语言中使用+".
Is this possible ? I have read that you cannot use '+' in Expression Language.
首先:您不需要计数器数组.只需 10 次即可(数字) - 也重复 10 次.但是你可以构建一个数组数组:
First: you wouldn't need an array for a counter. Just 10 would do (the number) - repeats 10 times too. But you could build an array of arrays:
var repArray = [];
for (var i=1;i<=10;i++) {
repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;
那么你应该可以使用
#{datasource.indexvar[0]}
绑定城市,
#{datasource.indexvar[1]}
绑定街道.等
有一点弄乱数组序列的危险,如果这是一个问题,您需要在此处更深入地使用对象.
Carries a little the danger of messing with the sequence of the array, if that's a concern you would need to dig deeper in using an Object here.