JQuery搜索使用单个搜索框组合文本框和下拉字段

时间:2016-05-19 05:33:29

标签: javascript jquery html model-view-controller kendo-ui

我有一个字段的下拉框和一个文本框搜索其他字段。我需要在一次搜索中组合这些搜索。下面的代码不会将两个搜索组合成单个搜索。我需要结合两个搜索结果并产生一个输出。我如何结合两种搜索?

function onSearch() {
    var q = $("#textboxsearch").val();
    var drop1;
    var drop = $("#dropdown option:selected").val() == "" ? 
        q : ($("#dropdown").val() == "True" ? true : false);

    var grid = $("#grid").data("kendoGrid");
    grid.dataSource.query({
        page: 1,
        pageSize: 10,
        filter: {
            logic: "or",
            filters: [
                { field: "Name", operator: "contains", value: q },
                { field: "Project", operator: "contains", value: q },
                { field: "Id", operator: "contains", value: q },
                { field: "Type", operator: "contains", value: q },
                { field: "Usage", operator: "contains", value: q },
                { field: "Builder", operator: "contains", value: q },
                { field: "Status", operator: "contains", value: q },
                { field: "Group", operator: "contains", value: q },
            ],                                         
            logic: "and",
            filters: [
                { field: "IsActive", operator: "contains", value: drop }
            ]
        }
    });
}                               

1 个答案:

答案 0 :(得分:0)

var drop = $("#dropdown option:selected").val() == "" ?  q : ($("#dropdown").val() == "True" ? true : false);

用下面的

替换下面的行
var drop = $("#dropdown").val();