copy contents view to 2 strings

回眸只為那壹抹淺笑 提交于 2019-12-25 05:13:33

问题


I have a view that is build based on a search . On a click of a button: I would like to copy the first 10 rows of the column "city" to one string. Between each city I would like to add the characters "\r" .So the result is a string like :"Rome \r Berlin \r Paris ..." The remaining rows (from 11 till the end) should be copied to another string.


回答1:


Something like this will work:

<xp:this.data>
   <xp:dominoView var="view2"
        viewName="<<viewName>>">
   </xp:dominoView>
</xp:this.data>

<xp:inputText>
    <xp:this.value><![CDATA[#{javascript:
     var length = view2.getEntryCount();
     var entries = view2.getAllEntries();
     var i = 0;
     var currentEntry = entries.getFirstEntry();
     var list = "";

     while(i < length)
     {
        list += currentEntry.getColumnValues().elementAt(1);

        currentEntry = entries.getNextEntry();
        i++;
     }

     return list;
}]]></xp:this.value>
</xp:inputText>

Replace <> with the name of your view. Add a check to see when you have 10 values and add to another string and place the "\r" value you want at the end of the string. You can also get the view inside the server side script as well depending on how you want to do this.

If this is for displaying pages of data there are controls such as the dataview that can be given a view as a datasource, told which columns to display and told how many rows to show per page.




回答2:


If you want to do this client side and are able to use jQuery you could do something like this, where you have to substitute the ControlName and ColimnId for your setup.

var string1="";
var string2="";


$("[id$='yourControlName'] tr td:nth-child(columnId)").each(function (i) {
    if (i==0) then string1=$(this).text()
    if (i<=10){
        string1 += "\r"+$(this).text
    }
    if (i==11) then string2=$(this).text()
    if (i>11) {
        string2 += "\r"+$(this).text    
    }
 });


来源:https://stackoverflow.com/questions/10895761/copy-contents-view-to-2-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!