3

我正在使用 kendo Multiselect,我想找到一种方法来搜索我的数据源的多个字段。这是我的实际代码。但它只适用于一个领域:

`
$scope.dataList = new kendo.data.DataSource({
    data:[{id: "1",name: "Doe, John",email: "John.Doe@example.com"}],
});
$scope.customOption = {
                dataSource: $scope.dataList,
                dataTextField: "name",
                dataValueField: "id",
                filter: "contains", 
                itemTemplate: '<span>#=id#</span>#=name#<i> #=email#</i>',
}
`

如您所见,我也在使用 AngularJS,我尝试搜索姓名和电子邮件。

4

1 回答 1

7
$("#id").kendoMultiSelect({
        placeholder: "Select products...",
        dataTextField: "name",
        dataValueField: "id",
        autoBind: false,
        filtering: function (e) {
            if (e.filter) {
                var value = e.filter.value
                var newFilter = {
                    filters: [
                        { field: "id", operator: "contains", value: value },
                        { field: "name", operator: "contains", value: value },
                        { field: "email", operator: "contains", value: value }
                    ],
                    logic: "or"
                }
                e.sender.dataSource.filter(newFilter)
                e.preventDefault()
            }
            e.preventDefault()
        },
        dataSource: {
            data:[
            {id: "1",name: "Doe, John",email: "John.Doe@example.com"},
            {id: "2",name: "sss, John",email: "sss.Doe@example.com"},
            {id: "3",name: "fff, John",email: "fff.Doe@example.com"},
            {id: "4",name: "ccc, John",email: "ccc.Doe@example.com"}
            ],
        },
        value: [
            {id: "1",name: "Doe, John"},
        ]
    });

请参阅 Kendo DataSourceMultiSelect的 API 文档。希望能帮助到你。

于 2016-04-13T13:19:07.890 回答