jquery - 将枚举值传递到jQuery网格过滤器

标签 jquery grails enums grid

这看起来确实很容易,但是还没有做到。

目前我有一个枚举:

enum LocationCodes{
  USA(3), Canada(4), Carribean(5), USPacific(6)
  NANPCodeGroup(int value) {this.value = value}
  private final int value
  public int value() {return value}
}

我的gsp中有一个jquery网格,其中有一个用于搜索的下拉列表
        <!-- table tag will hold our grid -->
        <table id="customer_list" class="scroll jqTable" cellpadding="0" cellspacing="0"></table>
        <!-- pager will hold our paginator -->
        <div id="customer_list_pager" class="scroll" style="text-align:center;"></div>

<script type="text/javascript">
        /* when the page has finished loading.. execute the follow */
        $(document).ready(function () {
            jQuery("#customer_list").jqGrid({
              url:'jq_customer_list',
              datatype: "json",
              colNames:['customer','location','id'],
              colModel:[
                {name:'customer'},
                {name:'location',stype:'select', searchoptions:{value:':All;USA:USA;Canada:Canada;Carribean:Carribean;USPacific:USPacific;'}},
                {name:'id', hidden:true}
              ],
              rowNum:2,
              rowList:[1,2,3,4],
              pager: jQuery('#customer_list_pager'),
              viewrecords: true,
              gridview: true
            });
            $("#customer_list").jqGrid('filterToolbar',{autosearch:true});
        });
        </script>

对于位置,我想输入枚举值。有什么想法吗?谢谢!

最佳答案

这应该给出用“;”分隔的枚举列表。

${LocationCodes?.values()?.collect{it.toString() + ':' + it.toString()}?.join(';')}

因此,您可以尝试执行以下操作:
searchoptions: {
    value: ":All;${LocationCodes?.values()?.collect{it.toString() + ':' + it.toString()}?.join(';')}" 
}

仔细检查引号的转义,但应该可以。 :)

关于jquery - 将枚举值传递到jQuery网格过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14401371/

相关文章:

jquery - JSON 解析器错误

validation - 如果 Grails 命令对象绑定(bind)不满足约束

javascript - 从 jQuery .ajax() 问题调用 Web 服务

grails - 使用Spring Security Core 3.0.0M1创建登录名

grails - 对WebSphere 7或8的Grails支持

java - 如何在Java中创建类似于 "dynamic enumerations"的常量分组?

enums - Rust 中逻辑上但非法的未初始化变量

java - GSON 正确序列化枚举,但将其反序列化为字符串

javascript - 如何让按钮漂浮在剑道小部件上

javascript - 查找包含特定 div 的部分元素的数据索引