【问题标题】:Refresh to repeat control not working normal after deleting 1 row删除1行后刷新重复控制不能正常工作
【发布时间】:2015-07-22 19:17:44
【问题描述】:

我在文档中有一个名为“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;

【问题讨论】:

    标签: javascript refresh xpages repeat


    【解决方案1】:

    另一种尝试可能是将重复链接与 viewScope 而不是文档:

    1) 在 beforeLoadPage/afterLoadPage 事件中:从文档中获取值,并将其放入 viewScope 变量中:

    // beforeLoadPage event:
    // ... get the doc
    viewScope.selectedTimes = doc.getItemValue("selectedTimes");
    

    2)在repeat控件中,使用viewScope:

    <xp:repeat value="#{viewScope.selectedTimes}"...
    

    3) 更新完成后,同时更新 viewScope 和文档:

    //...update the View Scope variable and get the document:
    doc.replaceItemValue("selectedTimes", viewScope.selectedTimes);
    

    如果将文档添加为 DataSource,这可能是一个提示:

    您是否将文档作为数据源包含在 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 中你得到一个字符串值:

    var sdtString =  getComponent("inputHidden1").getValue();
    

    如果您将时间值存储为 NotesDateTimes,您将在 Vector 中获得这种类型的值,并且 remove 方法将找不到字符串并且不会删除任何内容。

    // In a Vector<NotesDateTime> the String cannot be found:
    selectedTimes.remove(sdtString);
    

    确保删除与 Vector 中相同类型的值

    【讨论】:

    • 在注释文档中,删除过程正在完善,即使是我要删除的记录,它也会被删除,但即使在对重复控件进行部分刷新后,重复控件的最后一个值也会消失.在此之后,当我手动刷新浏览器窗口时,一切看起来都很完美。总之,刷新后重复控制也没有与笔记文档同步。
    • 如果您将文档添加为数据源:
    • 不,文档没有作为数据源添加,我只是将重复控制的代码附加到我的问题中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    相关资源
    最近更新 更多