2014-11-21 133 views
0

我目前在Kendo UI中遇到了一些問題。目前我有一個自動完成功能,我用它來獲得員工。我遇到的問題是我希望能夠使用多個詞(姓和名)來處理自動完成,例如'John Smith'。目前我的自動完成工作正常,如果輸入'john',它會在下面的下拉列表中顯示'John smith'以及包含單詞'john'的其他名稱。如果我輸入姓氏'史密斯'並且可以選擇'約翰史密斯',那麼同樣的作品可以。我想要做的是,當整個名字輸入'約翰史密斯'允許用戶選擇約翰史密斯,這意味着它仍然搜索這兩個詞。誰能幫忙?我將把我的代碼放在下面。Kendo UI自動完成,名稱搜索

謝謝。

//Autocomplete FeeEarner 
$("#FeeEarnerEmailSend").kendoAutoComplete({ 
    dataSource: new kendo.data.DataSource({ 
     serverFiltering: true, 
     transport: { 
      read: "/" + prefix + "/api/Session/GetEmployees", 
      parameterMap: function() { 
       return { id: $("#FeeEarnerEmailSend").data("kendoAutoComplete").value() }; 
      } 
     } 
    }), 
    dataTextField: 'FullName', 
    filter: "contains", 
    //placeholder: "Search...", 
    minLength: 3, 
    suggest: true, 
    select: function (e) { 
     var employeeAutoComplete = e.sender; 
     // this var is used in the Search button click event 
     selectedEmployeeDataItem = employeeAutoComplete.dataItem(e.item.index()); 
    }, 
    change: function() { 
     if ($.trim($("#FeeEarnerEmailSend").val()) == "") { 
      selectedEmployeeDataItem = null; 
     } 
    }, 
    dataBound: function (e) { 
     selectedEmployeeDataItem = e.sender.dataItem(0); 

    } 
}); 
+0

刪除minLength:3並進行搜索 – 2014-11-21 10:01:55

回答

1

我從你的問題中瞭解到,你想選擇名字,直到輸入全名。 這取決於自動完成小部件的「過濾器」和「minLength」屬性。

kendo自動完成支持的過濾器有:startswith,endswith和contains。

minLength: - 這取決於要求輸入多少個字符後應開始過濾。如果這被刪除,輸入一個字符後立即開始過濾。

由於名稱的長度不同,所以我擔心使用minLength過濾名稱可以滿足您的要求。與「filter」屬性相同,因爲它不支持「完全匹配」等任何內容(默認值= 1)。

因此,它決定了你如何明智地使用這兩個屬性來實現你的目標。

希望這會有所幫助。