JSON - 返回JSON到输入jqGrid的自动完成 [英] JSON - Returning JSON to a input jqGrid autocomplete

查看:281
本文介绍了JSON - 返回JSON到输入jqGrid的自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助在这件事情:我在jqGrid的做一个自动完成,而我需要做的是JSON返回自动完成输入。我在做这样的事情,但在我的自动完成只返回一个值,并在数据库中,我有一个以上的。有人可以帮我在这。我做这样的回报:

I need help in this thing: I'm doing a autocomplete in a jqGrid, and what I need to do is to return JSON to the input of autocomplete. I'm doing something like this, but in my autocomplete just return one value and in the database I have more than one. Somebody could help me in this. I'm doing the return like this:

...
header("Content-Type: application/json");
$i=0;
while($row = pg_fetch_array($result)) {
   $response->input['value']=$row[ac_fin_g];
   $i++;
}
echo json_encode($response);
...

但例如..我有在数据库中ac_fin_g值:{房子,家庭,蛋糕}。如果我写的字母O,出现在正确的是豪斯医生和HOME在我的自动完成,但这没有发生。当我改变code以上这个code(用于输入=何):

But for example.. I have in the database the values for ac_fin_g: {house, home, cake}. If I write the letter "O", the correct to appear is "HOUSE" and "HOME" in my autocomplete, but this is not happening. When I change the code above for this code (for the input="HO"):

...
header("Content-Type: application/json");
$i=0;
while($row = pg_fetch_array($result)) {
   $response->input[$i]['value']=$row[ac_fin_g];
   $i++;
}
echo json_encode($response);
...

我有正确的JSON:

I have the correct JSON:

{"input":[{"value":"HOME      "},{"value":"HOUSE     "}]}

我很抱歉,但我不知道如何解决这个问题。有人可以帮我?

I'm sorry but I don't know how to fix this. Somebody could help me?

更新:
由于@Oleg我想出如何做到这一点。我的情况是:

UPDATE: Thanks to @Oleg I figured out how to do this. For my case is:

$i=0;
while($row = pg_fetch_array($result)) {
$response[] = $row[ac_fin_g]; $i++;
}
echo json_encode($response);

:)

PS:此<一个href=\"http://stackoverflow.com/questions/1830264/how-can-i-convert-the-result-of-this-postgres-db-query-into-json-to-return-to-my\">link可能是有用的:)

PS: This link can be useful :)

推荐答案

服务器应该创建一个期望jQuery UI的JSON数据。对应于 jQuery UI的自动完成文档 JSON数据应

The server should create JSON data which expect jQuery UI. Corresponds to the jQuery UI Autocomplete documentation the JSON data should be

["HOME", "HOUSE"]

[{"label": "Home", "value": "HOME"}, {"label": "House", "value": "HOUSE"}]

而不是

{"input":[{"value":"HOME      "},{"value":"HOUSE     "}]}

您当前产生。有办法去code在客户端上任何其他的JSON数据,但它只是为了更好地遵循jQuery用户界面自动完成标准格式。

which you currently generate. There are way to decode any other JSON data on the client side, but it's better just to follow jQuery UI Autocomplete standard format.

这篇关于JSON - 返回JSON到输入jqGrid的自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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