jqGrid dataUrl下拉列表不刷新 [英] jqGrid dataUrl dropdown list not refreshing

查看:15
本文介绍了jqGrid dataUrl下拉列表不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Web 开发新手,正在开发我的第一个 ASP.NET MVC 3 应用程序.我正在使用 jqGrid 并注意到刷新页面不会刷新下拉列表中的值,直到我在另一个选项卡中打开同一页面,然后刷新第一个选项卡将获取更改的值.

I'm new to web development and working on my first ASP.NET MVC 3 app. I'm using jqGrid and noticed that refreshing the page does not refresh the values in the dropdownlist until I open the same page in another tab, then refreshing the first tab will pick up the changed values.

我有一个如下所示的控制器操作:

I've got a controller action that looks like this:

public JsonResult FavoriteToppings()
{
   var all = GetFavoriteToppings();
   return Json(all, JsonRequestBehavior.AllowGet);
}

我的 jqGrid 定义部分如下所示:

and I've the part of the jqGrid definition looks like this:

{ name: 'ToppingID', index: 'ToppingID', width: 200,
    editable: true, align: 'left', edittype: 'select', stype: 'select',
    editoptions: {
        dataUrl: '@Url.Action("FavoriteToppings", "Dessert")',
        buildSelect: createSelectList
    },
    searchoptions: {
        dataUrl: '@Url.Action("FavoriteToppings", "Dessert")',
        buildSelect: createSelectList,
        sopt: ['eq']
    }
},

createSelectList 看起来像这样:

createSelectList = function (data) {
    var response, s = '<select>', i, l, ri;
    if (typeof (data) === "string") {
        //var leng = data.length - 1;
        response = jQuery.parseJSON(data);
    }
    else {
        response = jQuery.parseJSON(data.responseText);
        s += '<option value="">Select...</option>';
    }

    if (response && response.length) {
        for (i = 0, l = response.length; i < l; i += 1) {
            ri = response[i];
            s += '<option value="' + ri + '">' + ri + '</option>';
        }
    }
    return s + '</select>';
}

我在编辑其中一个顶级名称时注意到了这一点.我将拼写错误的Hot Fugde"更改为Hot Fudge"并将其保存下来.当我刷新页面但过滤器下拉列表没有时,表中的基础数据会更新以显示正确拼写的顶部(即所有行都正确反映了更改).在第一次获取更改后,根本不会调用该操作.

I noticed this when editing one of the topping names. I changed the misspelled "Hot Fugde" to "Hot Fudge" and saved that off. The underlying data in the table gets updated to show the correctly spelled topping (i.e., all the rows correctly reflect the change) when I refresh the page but the filter dropdown doesn't. That action isn't called at all after the first time to pick up the change.

当我在浏览器的不同页面中打开同一页面时,会调用该操作.之后,刷新第一个选项卡将导致选择列表中显示正确拼写的条目.

When I do open the same page in a different page of the browser, then the action gets called. After that, refreshing the first tab will result in the correctly spelled entry showing up in the select list.

也许我只是在错误地处理这个问题.有什么指导吗?

Perhaps I'm just going about this incorrectly. Any guidance?

推荐答案

我觉得你得用

ajaxSelectOptions: { cache: false }

jqGrid 参数 设置附加参数 cache: false 对于 jqGrid 使用的 jQuery.ajax 如果它从中获取数据dataUrl 中的服务器.

jqGrid parameter to set additional parameter cache: false for the jQuery.ajax used by jqGrid if it get the data from the server from the dataUrl.

这篇关于jqGrid dataUrl下拉列表不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆