问题
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