在XPages中,我试图从视图中提取值,并根据该值通过复选框选择了一个值。

我有一个名为'viewpanel2'的视图,其中包含LoggerID,每个LoggerID由一个数字值组成。

我有一个按钮,当选中LoggerID旁边的复选框并单击该按钮时,会使用javascript从视图中提取值。我遇到的问题是,它不断在视图中打印所有LoggerID的所有值,而不仅仅是已选择的一个。

这是按钮的代码:

var viewPanel = getComponent("viewPanel2"); //in the view panel select the check box
var docIDArray = viewPanel.getSelectedIds(); //get that selected ID
for (i = 0; i < docIDArray.length; i++) {
    var docId = docIDArray[0];
    var doc = database.getDocumentByID(docId);
    var moo = doc.getItemValue("LoggerID"); //selected ID is defined

    var vw = database.getView('BrowserStats'); //Get the Notesview
    var vwEntries = vw.getAllEntries(); //Get handle of all entries
    var vwCount = vwEntries.getCount(); //Get the Count to use as uBound
    var vwEntry = vwEntries.getFirstEntry(); //Get first value

    //Get the first entry and get the column value of the first entry
    var plot_LoggerID = vwEntry.getColumnValues().elementAt(2);

    for (var x = 1; x < vwCount; x++) {
    //Looping through all the entries and collect the column values
    vwEntry = vwEntries.getNextEntry(vwEntry);
    plot_LoggerID = plot_LoggerID + "," + vwEntry.getColumnValues().elementAt(2);
    }
    //comparing the entries to the selected ID and if found extracting the values for LoggerID
}
if (moo = vwEntry) {
    getComponent("extracted_LoggerID").setValue("["+plot_LoggerID+"]");
} else {
    print = ("no data available");
}


我相信我的if条件无法正常工作。谁能提出解决方案?

最佳答案

您正在做作业,而不是比较。做这个:

if (moo === vwEntry) {


或者,如果它们属于同一类型,则应使用“ ===”。

09-19 09:37