0

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

我有一个名为“viewpanel2”的视图,其中包含LoggerIDs,每个LoggerID都由一个数值组成。

I have a button which extracts values from the view using javascript when a check box next to the LoggerIDis selected and the button is clicked. 我遇到的问题是它不断打印LoggerID视图中所有 s 的所有值,而不仅仅是已选择的一个。

这是按钮的代码:

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 条件不起作用。任何人都可以提出解决方案吗?

4

3 回答 3

7

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

if (moo === vwEntry) {

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

于 2013-06-06T15:45:16.607 回答
2

你错的部分在那里:

if (moo = vwEntry) {

主要原因是=JavaScript 中的单点登录意味着您为变量赋值

您应该使用==比较两个值或===比较需要相同的两个值。



Javascript 符号

=

是一个任务。


==

是一个比较


===

是您希望值相同(相同的类型)的比较。

于 2013-06-06T15:56:13.210 回答
0

这是工作代码。我相信

var doc = database.getDocumentByID(docId); 

表示获取所选文档的信息并

var moo = doc.getItemValue("LoggerID"); 

说你想要哪个文件。然后不需要 if 语句,你可以简单地说

getComponent("extracted_LoggerID").setValue(moo); 

它采用该文档 ID,进入视图并提取所选文档 ID 的数据。

整个工作代码看起来像这样

  var viewPanel = getComponent("viewPanel1"); //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[i];
   var doc = database.getDocumentByID(docId);
      var moo = doc.getItemValue("LoggerID"); //selected ID is defined
      var h = doc.getItemValue("G");
      var e = doc.getItemValue("IE");
      var f = doc.getItemValue("FF");
      var c = doc.getItemValue("CH");
      var s = doc.getItemValue("SA");
      var o = doc.getItemValue("OP");
      var l = doc.getItemValue("LM");

//comparing the entries to the selected ID and if found extracting the values for LoggerID

      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);
      var plot_G = vwEntry.getColumnValues().elementAt(5);    
      var plot_IE = vwEntry.getColumnValues().elementAt(6);    
      var plot_FF = vwEntry.getColumnValues().elementAt(7);    
      var plot_CH = vwEntry.getColumnValues().elementAt(8);    
      var plot_SA = vwEntry.getColumnValues().elementAt(9);
      var plot_OP = vwEntry.getColumnValues().elementAt(10);    
      var plot_LM = vwEntry.getColumnValues().elementAt(11);            

      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);
      plot_G = plot_G + "," + vwEntry.getColumnValues().elementAt(5);    
      plot_IE = plot_IE + "," + vwEntry.getColumnValues().elementAt(6);    
      plot_FF = plot_FF + "," + vwEntry.getColumnValues().elementAt(7);    
      plot_CH = plot_CH + "," + vwEntry.getColumnValues().elementAt(8);    
      plot_SA = plot_SA + "," + vwEntry.getColumnValues().elementAt(9);    
      plot_OP = plot_OP + "," + vwEntry.getColumnValues().elementAt(10);    
      plot_LM = plot_LM + "," + vwEntry.getColumnValues().elementAt(11);    

     }

      getComponent("extracted_LoggerID").setValue(moo);
      getComponent("extracted_G").setValue(h);
      getComponent("extracted_IE").setValue(e);    
      getComponent("extracted_FF").setValue(f);    
      getComponent("extracted_CH").setValue(c);    
      getComponent("extracted_SA").setValue(s);    
      getComponent("extracted_OP").setValue(o);   
      getComponent("extracted_LM").setValue(l);       
    }

看起来我从来不需要 if 语句。

于 2013-06-28T10:45:03.707 回答