记录OMgrid的选中行序号ID待数组中,并通过URL,将数组字符串化后传递到控制器

本文详细介绍了如何使用OmGrid组件在表格中实现选中行ID的选择和传递过程,包括数据存储、事件监听以及参数组合,旨在简化用户在前端应用中进行数据操作的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//可将选中行的ID,组合成一个字符串参数,传递到控制器


var selectIds = [];//存储选中的序号数组        //同理其他列数据也可以存储在数组中

 $(document).ready(function() {

$('#grid').omGrid({
                title : '明细内容',
                limit : 20,              
                showIndex : true,            
                singleSelect : false,
                colModel : [ {header : '顺序号',   name : 'inventoryItemId', width : 30, align : 'center',sort:'clientSide'},
                             {header : '物料编码', name : 'inventoryItemCode', width : 150, align : 'center',sort:'clientSide'},                             
                             {header : '创建者', name : 'createdBy', width : 'autoExpand', align : 'left',sort:'clientSide'}
                           ],
                    onRowSelect : function(index, data){
                        if($.inArray(data.inventoryItemId, selectIds)== -1)
                               selectIds.push(data.inventoryItemId);
                    },
                    onRowDeselect : function(index, data){
                        var i = $.inArray(data.inventoryItemId, selectIds);
                        selectIds.splice(i,1);

                    },
                    //还原过去选中的记录
                    onRefresh : function(nowpage, records){
                        var len = selectIds.length;
                        var indexs = [], index =-1;
                        for(var i=0; i<len; i++){
                           $.each(records, function(n,item){
                               if(item.inventoryItemId === selectIds[i]){
                                         indexs.push(n);
                               }
                           });
                        }
                        
                        $("#grid").omGrid("setSelections", indexs);
                    }
            });

         });
                
//---------------------------------------调用----------------------------------

onClose:function(v){                           
                           if(v)
                           {
                                   var text="";
                                $.each(selectIds,function(i,item){
                                    text = text+ item+",";
                                }
);
                                //alert("您选择的记录有:"+text);//以逗号分隔开来
                                var text_encode =  encodeURIComponent(text);
                                   pathUrLupdate +="&selectIds="+text_encode;
                           
                                     
                                     $('#set_item_OF_flag').omButton('disable'),//失效按钮,避免多次提交//pathUrLupdate中传递组合成的ID字符串text_encode
                                   $('#formUpdateMeasureUnit').omAjaxSubmit({     url : pathUrLupdate,
                                                         target: '#output',         
                                                                                
                                                        success: showResponseUpdateFlag
                                    });
                            }
                          }//onClose


Admin::script( <<<EOT $(document).ready(function() { console.log('Document is ready'); console.log('.plan_id exists:', $('.plan_id').length > 0); console.log('#school-container exists:', $('#school-container').length > 0); setTimeout(function() { $('.plan_id').change(function() { var planId = $(this).val(); $.get("/tools/plan_school",{q : planId}, function (data) { $('#school-container').empty(); var temp = ''; $.each(data, function(index, school) { temp += '<div class="form-group"><label for="name" class="col-sm-4 control-label">'+school.text+'</label><div class="col-sm-6"><div class="input-group"><span class="input-group-addon"><i class="fa fa-pencil fa-fw"></i></span><input type="text" id="school_id" name="school_id_'+school.id+'" value="" class="form-control name" placeholder="输入 编号" /></div></div></div>'; }); $('#school-container').append(temp); }); },1000); }); }); EOT ); 我这段代码在进入页面的时候会报错VM4707:13 Uncaught SyntaxError: Invalid or unexpected token at eval (<anonymous>) at n.globalEval (jQuery-2.1.4.min.js:2:2538) at n.fn.init.domManip (jQuery-2.1.4.min.js:3:17225) at n.fn.init.append (jQuery-2.1.4.min.js:3:14908) at HTMLScriptElement.cb (jquery.pjax.js:792:19) at next (jquery.pjax.js:803:12) at executeScriptTags (jquery.pjax.js:805:5) at options.success (jquery.pjax.js:324:5) at j (jQuery-2.1.4.min.js:2:26925) at Object.fireWith [as resolveWith] (jQuery-2.1.4.min.js:2:27738) 重新刷新页面以后就可以正常显示控制台能够正确打印Document is ready create:1333 .plan_id exists: true create:1334 #school-container exists: true
最新发布
06-05
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值