InfoPath中repeationg section动态填充数据

时间:2022-04-22
本文章向大家介绍InfoPath中repeationg section动态填充数据,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

项目后台使用的是基于InfoPath的后台管理系统。后台主要是生成CMS系统需要的XML文件,但是有的内容和其他的内容有关联。为了减少编辑人员的操作难度,所有相关的内容,都需要自定义开发InfoPath,支持动态加载关联的数据内容。InfoPath界面如下:

Insert Type和Content Type是从Config DataObject里面动态读取,content type右边的字段是根据content type左边的字段来过滤显示内容了。这个字段是通过Detail DataObject来读取的。conent type右边的字段是一个drop list box,也就是dropdown list下拉框。通过选择不同的字段,填充下面的title,abstract,以及最下面的Image Url和Image Tooltip。这个四个字段的数据是动态从RelatedContent DataObject中读取的。因为整个的大的section可以重复,所以最开始实现起来,问题还是蛮多的。主要使用到了current()函数,后续博客里面将介绍,如何在repeating section中是使用current()函数,达到指定的section绑定不同的数据。

通过使用current()函数,title,abstact,image url和image tooltip都可以正常的填充数据,但是保存好infopath之后,用户重新打开,发现前面提到的四个字段都为空,因为我是对这个四个字段动态绑定RelatedContent数据源,并且是根据id(content type右边的那个字段)来筛选显示数据的。但是不知道为什么,infopath保存不了上述四个字段值。我最后找到一个比较简陋的办法时,将那四个字段复制一份,名称都以Populate开始,就是这四个字段使用current()函数去动态加载数据,而正常的title,abstract,image url和image tooltip不去动态加载数据,和普通的infopath字段一样。然后需要用户最后点击最下面的“Binding Data”按钮,然后将Populate的值全部复制到普通的四个字段中。这样得以保存infopath中的数据。

“Binding Data”按钮事件的内部代码如下:

e.Source.selectSingleNode("title").text=e.Source.selectSingleNode("populatetitle").text; e.Source.selectSingleNode("abstract").text=e.Source.selectSingleNode("populateabstract").text; e.Source.selectSingleNode("image/@url").text=e.Source.selectSingleNode("image/@populateurl").text; e.Source.selectSingleNode("image/@tooltip").text=e.Source.selectSingleNode("image/@populatetooltip").text;
<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

本身Main Source的xml结构如下:

<root> <contentItems configXML=""> <content inserttype="" contenttype="" id=""> <title></title> <abstract></abstract> <link url="" target=""></link> <image url="" tooltip=""></image> </content> <content inserttype="" contenttype="" id=""> <title></title> <abstract></abstract> <link url="" target=""></link> <image url="" tooltip=""></image> </content> <content inserttype="" contenttype="" id=""> <title></title> <abstract></abstract> <link url="" target=""></link> <image url="" tooltip=""></image> </content> </contentItems> </root>
<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->