以编程方式将自定义控件中的编辑框绑定到表单字段

发布于 2024-12-29 06:13:07 字数 736 浏览 1 评论 0原文

我有一个注释表单,其中包含一系列字段,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦回梦里 2025-01-05 06:13:07

首先:您不需要一个计数器数组。只要 10 就可以了(数字)——也重复 10 次。但是您可以构建一个数组的数组:

var repArray = [];
for (var i=1;i<=10;i++) {
   repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;

然后您应该能够使用

#{datasource.indexvar[0]}

绑定城市、

#{datasource.indexvar[1]}

绑定街道。等等。

存在一些扰乱数组顺序的危险,如果这是一个问题,您需要在此处更深入地使用对象。

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;

then you should be able to use

#{datasource.indexvar[0]}

to bind city,

#{datasource.indexvar[1]}

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.

撧情箌佬 2025-01-05 06:13:07

计算为 javascript 并使用类似

var viewnam = "#{" +  (compositeData.searchVar )+ "}"
return viewnam

确保这是在自定义控件中的页面加载时计算的

compute to javascript and use something like

var viewnam = "#{" +  (compositeData.searchVar )+ "}"
return viewnam

make sure this is computed on page load in the custom control

独自唱情﹋歌 2025-01-05 06:13:07

我从未能够在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文