我在文档中有一个名为“ selectedTime”的字段,该字段存储用户添加的选定计时。添加时间工作完美。这是后端。
现在我将解释从前端选择日期的问题。我给按钮添加了添加时间。日期时间的自定义控件会添加到单击添加按钮的重复控件上,即使我签入文档也显示了选定时间的列表。
现在,如果我想从重复控件中随机删除一个选定的时间,它将从文档中删除该特定记录,但是在页面上重复的最后一个记录消失了,
我以为这是重复控制的部分刷新的问题,我什至尝试过但没有结果。完全刷新会中断页面。
删除按钮的Java脚本代码
`var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
if(selectedTimes != null){
var sdtString = getComponent("inputHidden1").getValue();
if(selectedTimes.contains(sdtString))
selectedTimes.remove(sdtString);
doc.replaceItemValue("selectedTimes",selectedTimes);
doc.save();
};
var url:XSPUrl = context.getUrl();
view.postScript("window.refresh('"+url+"')");`
我知道很难理解我要解释的内容,但是对此提出的任何建议将不胜感激。
即使有人想删除文档的字段值,在我的情况下,字段名称为“ selectedTimes”,并且这些值在重复控制中添加了时间,请共享。
编辑1:
//Repeat Control
var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
return selectedTimes;
另一种尝试是将重复链接与viewScope而不是文档链接:
1)在beforeLoadPage / afterLoadPage事件中:从文档中获取值,并将其放在viewScope变量中:
// beforeLoadPage event:
// ... get the doc
viewScope.selectedTimes = doc.getItemValue("selectedTimes");
2)在重复控件中,使用viewScope:
<xp:repeat value="#{viewScope.selectedTimes}"...
3)更新完成后,同时更新viewScope和文档:
//...update the View Scope variable and get the document:
doc.replaceItemValue("selectedTimes", viewScope.selectedTimes);
如果文档将作为数据源添加,这可能是一个提示:
您是否将XPage中包含的文档作为数据源?在这种情况下,请尝试从数据库获取并更新NotesXspDocument而不是Document:
XPage:
<xp:this.data>
<xp:dominoDocument var="xspDocument"
action="editDocument"
documentId="#{param.unid}">
</xp:dominoDocument>
</xp:this.data>
SSJS代码:直接使用XspDocument
var selectedTimes:java.util.Vector = xspDocument.getItemValue("selectedTimes");
...
xspDocument.replaceItemValue("selectedTimes", selectedTimes);
如果不能从文档中删除该值,则可能是一个提示:
在sdtString中,您将获得一个String值:
var sdtString = getComponent("inputHidden1").getValue();
如果您将时间值存储为NotesDateTimes,则将在Vector中获得这种类型的值,而remove方法将找不到String,并且不会删除任何内容。
// In a Vector<NotesDateTime> the String cannot be found:
selectedTimes.remove(sdtString);
确保删除与向量中相同类型的值
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句