以编程方式将自定义控件中的编辑框绑定到表单字段
我有一个注释表单,其中包含一系列字段,例如 city_1、city_2、city_3 等。
我有一个 XPage,在该 XPage 上有一个重复。
重复基于具有十个值 1 - 10 的数组
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
return(repArray) ;
在重复中,我有一个自定义控件,用于显示 city_1 到 city_10 字段
重复有一个传入的自定义属性 docdatasource 它还具有一个名为 cityFieldName 的字符串自定义属性,该属性是使用重复计算的 集合名称,以便在第一个重复行中为 city_1,在第二个重复行中为 city_2 等。
自定义控件上的可编辑文本字段使用 EL 公式绑定 compositeData.docdatasource[compositeData.cityFieldName]
这工作正常,但每次添加新字段时,我都必须记住创建一个新的自定义属性,然后在父页面上引用它。
我希望能够简单地计算数据绑定,例如
compositeData.docdatasource['city_' + indexvar]
其中 indexvar 是表示当前行号的变量。
这可能吗?我读到不能在表达式语言中使用“+”。
I have a notes form with a series of fields such as city_1, city_2, city_3 etc.
I have an XPage and on that XPage I have a repeat.
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) ;
}
return(repArray) ;
Within the repeat I have a custom control which is used to surface the fields city_1 through city_10
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..
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]
where indexvar is a variable representing the current row number.
Is this possible ? I have read that you cannot use '+' in Expression Language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先:您不需要一个计数器数组。只要 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:
then you should be able to use
to bind city,
to bind street. etc.
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.
计算为 javascript 并使用类似
确保这是在自定义控件中的页面加载时计算的
compute to javascript and use something like
make sure this is computed on page load in the custom control
我从未能够在 EL 中进行加法,但我非常成功地简单地计算自定义控件外部的字段名称,然后将这些值传递到自定义控件中。
如果您愿意,我可以从我提供的演示文稿中向您发送一些工作代码。
I was never able to do the addition within EL but I have been very successful with simply computing the field names outside the custom control and then passing those values into the custom control.
I can send you some working code if you wish from a presentation I gave.