0

这似乎很容易,但一直没能做到。

目前我有一个枚举:

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>

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

4

2 回答 2

1

这应该给出由';'分隔的枚举列表

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

所以你可以尝试这样的事情:

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

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

于 2013-01-21T17:07:50.380 回答
0

这行得通吗?(假设它是普惠制)

{ name:'location',
  stype:'select',
  searchoptions:{ value:'":All;${LocationCodes.values().collect { "$it:${it.value()}" }.join(';')};"'}},

应该给你

':All;USA:3,Canada:4,Carribean:5,USPacific:6;'

但我还没有测试过:-/

于 2013-01-18T14:55:59.567 回答