jqgrid/如何创建动态加载选择选项的选择框 [英] jqgrid/ how to create selectbox dynamically loading select options

查看:115
本文介绍了jqgrid/如何创建动态加载选择选项的选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个选择框,该选择框使用json数据动态加载选择选项.

I want to create a selectbox which loads select options dynamically using json data.

合作ID"是一个选择框,我要做的就是从其他数据库表中获取数据,因此我将URL放在"dataURL"中并使用"buildselect"来获取json数据. 测试时,我的选择框中没有任何选项.我想我的代码中遗漏了某些东西或某些地方有问题.

The 'cooperation id' is a selectbox and all i want to do is getting data from other database table so i put the url in the 'dataURL' and use the 'buildselect' to get json data. I've got no options in selectbox when i tested. I think i miss something or something is wrong in my code.

下面是我的代码.

jQuery(function($) {

            jQuery(grid_selector).jqGrid({
                url: '/jqGrid/merchantEstablishmentList',
                datatype: 'json',
                height: 'auto', autowidth: true,
                colNames:
                [   
                    'Establishment ID',
                    'Establish Name',
                    'Corporation ID'
                ],
        colModel:
                [
                    {name:'ESTABLISHMENT_ID',index:'ESTABLISHMENT_ID',  editable:true, sortable:false,search: false},
                    {name:'ESTABLISHMENT_NAME',index:'ESTABLISHMENT_NAME', editable:true, sortable:false,search: false},
                    {name:'CORPORATE_ID',index:'CORPORATE_ID', sortable:false,edittype:"select", editable:true, search: false, editoptions: {
                        dataUrl : '/jqGrid/getMerchantsID/?m_type=corp.html?type=json'
                        ,buildSelect:function (data) {
                            value = jQuery.parseJSON(data).combo;
                            var result = '<select>';
                            for(var idx=0; idx < value.length; idx++) {
                                result += '<option value="' + value[idx] + '">' + value[idx] + '</option>';
                            }
                            result += '</select>';
                            return result;
                        }
                    }}

推荐答案

如果在问题文本中附加/jqGrid/getMerchantsID/?m_type=corp.html?type=json的答案,是否可以?

If would be good if you append the text of your question with the response from /jqGrid/getMerchantsID/?m_type=corp.html?type=json.

您使用哪个版本的jqGrid?如果使用 jqGrid的当前版本,并且服务器返回正确格式的数据,则应使用data.combo而不是jQuery.parseJSON(data).combo.另外,您应该在value之前添加var.您当前的buildSelect代码隐式声明了全局 value变量.

Which version of jqGrid you use? If you use the current version of jqGrid and if your server returns correct formatted data then you should use data.combo instead of jQuery.parseJSON(data).combo. Additionally you should add var before value. Your current code of buildSelect declare implicitly global value variable.

这篇关于jqgrid/如何创建动态加载选择选项的选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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