如何在Ajax调用中在运行时获取变量值

时间:2013-02-08 05:41:28

标签: jquery asp.net ajax jqgrid

我在java脚本代码中声明了一个变量来获取Jqgrid中filtertoolbar字段的值。这是变量声明:

var filter = $("#gridId").jqGrid('getGridParam', 'postData').filters;
console.log(filter);

最初过滤器工具栏在加载网格时为空,因此它在控制台输出中提供{"groupOp":"AND","rules":[]}。这没关系,但是当我们在加载网格后输入过滤值时,它没有改变它的响应。没有回应我在firebug中获取过滤器事件.. 这是我的完整代码:

$(function () {
var gridData = null;
var nn = null;
$.ajax({
    url: 'Default.aspx/MyMethod',
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    type: 'POST',
    success: function (ReportDataNew, textStatus, XMLHttpRequest) {
        //debugger;
        gridData = JSON.parse(ReportDataNew.d);
        //console.log(gridData);
        //alert(gridData.length);


        $("#gridId").jqGrid({
            data: gridData,
            datatype: "local",
            height: '100%',
            autowidth: true,
            ignoreCase: true,
            rowNum: 100,
            rowList: [100, 200, 300],
            colNames: ['UserName', 'Ordinal', 'Extension'],
            colModel: [
                       { name: 'username', index: 'username', width: 100, sortable: true, align: 'center' },
                       { name: 'ordinal', index: 'ordinal', width: 100, sortable: true, align: 'center' },
                       { name: 'extension', index: 'extension', width: 100, sortable: true, align: 'center' },
                      ],
            pager: '#gridpager',
            viewrecords: true,
            toppager: true,
            loadtext: 'Loading...'
            //grouping: true,
            //groupingView: {
            //groupField: ['extension']
            //}


        });
        $('#gridId').jqGrid('navGrid', '#gridpager',
                                 { edit: false, add: false, del: false, refreshtext: "Reload", view: false, searchtext: "Search", cloneToTop: true },
                                 {}, {}, {}, { caption: "Search", closeOnEscape: true, multipleSearch: true, closeAfterSearch: true, overlay: false });

        setSearchSelect('extension');
        grid.jqGrid('setColProp', 'Name',
        {
            searchoptions: {
                sopt: ['cn'],
                dataInit: function (elem) {
                    $(elem).autocomplete({
                        source: getUniqueNames('Name'),
                        delay: 0,
                        minLength: 0
                    });
                }
            }
        });


        jQuery("#gridId").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "eq" });
        jQuery("#gridId")[0].triggerToolbar();

        console.log(gridData);

        var filter = $("#gridId").jqGrid('getGridParam', 'postData').filters;
        console.log(filter);

我已将此代码放入代码的head部分,以及网格加载代码,我的网格在本地加载。

先生,我需要'过滤'变量的值......

提前完成..

0 个答案:

没有答案