【问题标题】:xpages typeahead autocompletexpages 预输入自动完成
【发布时间】:2014-05-07 14:36:38
【问题描述】:

我无法自动完成编辑框。我想从另一个数据库中取名字。我将我的代码写到了 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;

【问题讨论】:

  • 在什么情况下它不起作用?你有错误吗?如果是这样,请编辑您的问题以包括产生的任何错误。或者举一个输入、预期输出和实际输出的例子。
  • 当您将查询粘贴到该数据库的搜索框中时,您需要获得结果。你呢?

标签: autocomplete xpages typeahead xpages-ssjs


【解决方案1】:

你的代码有很多问题:

  1. 查询无法返回任何结果,因为您的字段中有空格
  2. 您真的需要 FTSearch 来返回值而不是排序视图吗?
  3. 预输入 - 顾名思义 - 显示从左到右匹配的值,而不是某个子字符串。如果您需要,您需要使用 Ajax 推出自己的 typeahead 功能
  4. typeahead 函数不带参数,因此您的lupkey 不会去任何地方。该函数需要返回所有值,XPages 将进行匹配
  5. 不要将一个一个复制到一个数组中进行排序,而是将返回的 Vector() 复制到一个 TreeSet() 中。这是一行,对其进行排序并删除重复项

要使其正常工作,请检查基于 dojo 的 this example,之前是 asked here。您将需要 REST 控件

【讨论】:

    【解决方案2】:

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

    //var目录:NotesDatabase = session.getDatabase(database.getServer(), "names.nsf");

    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);
        //}
    };
    
    
    
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多