xpages typeahead自动完成

时间:2014-05-07 14:36:38

标签: autocomplete xpages typeahead xpages-ssjs

我无法做一个自动编辑框。我想从另一个数据库中获取名称。我把我的代码写入了typeahead的值列表。但它不起作用。我使用相同的服务器但不同的数据库。任何人帮助我?这是我的代码:

//Getting the view containing a document for each of the employees
var searchView:NotesView = session.getDatabase("servername","test/application name.nsf")
.getView("viewname");

// Creating a Lotus Notes search query. Notice the reference to lupkey!
var query = "(FIELD Ad Soyad CONTAINS *" + lupkey +"*)";

// Creating an array to store hits in
var searchOutput:Array = ["å","åå"];

// Doing the actual search
var hits = searchView.FTSearch(query);

var entries = searchView.getAllEntries();
var entry = entries.getFirstEntry();

//Sort the array manually, since Notes doesn't want to sort them alphabetically
for (i=0; i<hits; i++) {
searchOutput.push(entry.getColumnValues()[0]);
entry = entries.getNextEntry();
}
searchOutput.sort();

// Build the resulting output HTML code
var result = "<ul><li><span class='informal'>Suggestions:</span></li></ul>";

var limit = Math.min(hits,20);
for (j=0; j<limit; j++) {
var name = searchOutput[j].toString();
var start = name.indexOfIgnoreCase(lupkey)
var stop = start + lupkey.length;
//Make the matching part of the name bold
name = name.insert("</b>",stop).insert("<b>",start);
result += "<li>" + name + "</li>"; 
}

result += "</ul>";
return result;

2 个答案:

答案 0 :(得分:1)

您的代码存在很多问题:

  1. 由于您的字段中有空格,查询无法返回任何结果
  2. 您真的需要FTSearch来返回值而不是排序视图吗?
  3. typeahead - 如名称所示 - 呈现从左到右匹配的值,而不是某个子字符串。如果您需要,您需要使用Ajax
  4. 滚动自己的预先输入功能
  5. 预先输入功能没有参数,因此lupkey无法进入任何地方。该函数需要返回所有值,XPage将执行匹配
  6. 不是逐个复制到数组中进行排序,而是将返回的Vector()复制到TreeSet()中。这是一行,对其进行排序并删除重复项
  7. 为了让它正常工作,请检查基于道场的this exampleasked here。您将需要REST控件

答案 1 :(得分:0)

我是这样做的 var directoryTypeahead = function(searchValue:string){     //更新以下行以指向您的真实目录

// var directory:NotesDatabase = session.getDatabase(database.getServer(),&#34; names.nsf&#34;);

var directory:NotesDatabase = session.getDatabase(database.getServer(), "org/test.nsf");

var allUsers:NotesView = directory.getView("SVFHP2");

var matches = {};
var includeForm = {
    Person: true,
    Group: true


}

searchValue = searchValue.replace("I","i")      
var matchingEntries:NotesViewEntryCollection = allUsers.getAllEntriesByKey(searchValue, false);
var entry:NotesViewEntry = matchingEntries.getFirstEntry();
var resultCount:int = 0;


while (entry != null) {

    var matchDoc:NotesDocument = entry.getDocument();
    var matchType:string = matchDoc.getItemValueString("Form");
    //if (includeForm[matchType]) { // ignore if not person or group
        var fullName:string = matchDoc.getItemValue("Name").elementAt(0) + " " + matchDoc.getItemValue("Title").elementAt(0);
        if (!(matches[fullName])) { // skip if already stored
            resultCount++;
            var matchName:NotesName = session.createName(fullName);
            matches[fullName] = {
                cn: matchName.getCommon(),
                photo: matchDoc.getItemValueString("Photo"),
                job: matchDoc.getItemValueString("sum"),
                email: matchDoc.getItemValueString("email"),



            }
        }           
//  }
    /*if (resultCount > 15) {
        entry = null; // limit the results to first 10 found
    }
    else {*/
        entry = matchingEntries.getNextEntry(entry);
    //}
};





}
相关问题