天天看點

InfoPath中repeationg section動态填充資料

項目

背景使用的是基于infopath的背景管理系統。背景主要是生成cms系統需要的xml檔案,但是有的内容和其他的内容有關聯。為了減少編輯人員的操作

難度,所有相關的内容,都需要自定義開發infopath,支援動态加載關聯的資料内容。infopath界面如下:

InfoPath中repeationg section動态填充資料

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;

本身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>