以编程方式将自定义控件中的编辑框绑定到表单域 [英] Binding an edit box within a custom control to a form field programatically

查看:31
本文介绍了以编程方式将自定义控件中的编辑框绑定到表单域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个笔记表单,其中包含一系列字段,例如 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.

这篇关于以编程方式将自定义控件中的编辑框绑定到表单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆