我有以下代码:
$("#perform_search").click(function() {
var postdata = $("#translationsList").jqGrid('getGridParam','postData');
postdata._search = true;
postdata.searchString = $("#auto_complete_search").val();
console.log('postdata._search: ' + postdata._search);
jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});
当我单击 ID 为 perform_search
的按钮时,生成的 URL 如下,并且从具有 id 的文本字段中提取值 searchString=hello
auto_complete_search
:
[域名]/translations_feed.php?language_cd=EN
&_search=false&nd=1308754288459&rows=20&page=1&sidx=phrase& ;sord=asc&searchString=hello
...并且应该发生的是 URL 字符串有_search=true
,但正如您从示例 URL 中看到的,传递的值是 _search=false
注意:第 5 行,我在其中将 postdata._search
的值输出到控制台,控制台按预期显示 postdata._search: true
,因此看起来按预期工作。
似乎所有其他参数都很好地通过了。
更新
看来,如果我第一次使用内置搜索按钮(jqGrid 中的小放大镜图标),那就正确设置了“_search=true”参数 - 之后我的按钮就可以正常工作了。不确定两者之间的联系是什么,但本质上似乎我的参数仍然被忽略。例如,如果我通过放大镜进行搜索,并更改我的 JavaScript,以便第 5 行读取 postdata._search = false
它会传递 _search=true
(换句话说) ,第 5 行似乎被完全忽略)。
想知道我是否只是在 postdata
上设置了错误的变量
I have the following code:
$("#perform_search").click(function() {
var postdata = $("#translationsList").jqGrid('getGridParam','postData');
postdata._search = true;
postdata.searchString = $("#auto_complete_search").val();
console.log('postdata._search: ' + postdata._search);
jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});
When I click on the button with ID perform_search
the resulting URL is below, and the value searchString=hello
is pulled from a text field with an id of auto_complete_search
:
[domainname]/translations_feed.php?language_cd=EN
&_search=false&nd=1308754288459&rows=20&page=1&sidx=phrase&sord=asc&searchString=hello
... and what's supposed to happen is that the URL string has _search=true
, but as you can see from the sample URL, the value being passed is _search=false
NOTE: line 5, where I output the value of postdata._search
to the console, the console shows postdata._search: true
as expected, so that appears to be working as expected.
Seems like all other params are passing through just fine.
UPDATE
Seems that, if I first use the built-in search button (the little magnifying glass icon in jqGrid), that is sets the "_search=true" param correctly - and after that my button works fine. Not sure what the connection between to the two is, but essentially it seems as if my param is still being ignored either way. For example, if I do a search via the magnifying glass, and change my javascript so that LINE 5 reads postdata._search = false
it passes _search=true
(in other words, LINE 5 seems to be ignored completely).
Wondering if I'm simply setting the wrong variable on postdata
发布评论
评论(1)
我已经回答了封闭式问题 就像你的问题一样。问题是您应该在 jqGrid 本身上设置
search
参数,而不是尝试以这种方式更改 postData。换句话说,要将
_search
设置为true
,您应该将 jqGrid 的search
参数设置为true
并且不设置任何直接使用postData
的属性。同样,您不应设置postData
的page
参数。请改用rowNum
参数。所以,你的代码应该更简单:
I answered an already closed question like yours. The problem is that you should be setting the
search
parameter on the jqGrid itself, and not trying to alter the postData in this way.In other words, to set
_search
astrue
you should setsearch
parameter of jqGrid totrue
and not set any properties ofpostData
directly. Similarly, you should not setpage
parameter ofpostData
. Instead use therowNum
parameter.So, your code should be much simpler: