一只会飞的白菜 2017-11-05 11:13 采纳率: 0%
浏览 8764

bootstrap getSelections 方法获取不到值

   <script type="text/javascript">
        $(function(){
            //编辑表格
            $('#table').bootstrapTable({
                //数据来源的网址
                url:'/index.xhtml',
                method: 'post',
                editable:true,//开启编辑模式
                clickToSelect: true,
                showPaginationSwitch:true, //显示分页切换按钮 
                search: true,  //显示检索框
                showRefresh: true,  //显示刷新按钮
                showToggle:true, //显示切换按钮来切换列表/卡片视图
                pagination: true,  
                pageList: [5,25],  
                pageSize:5,  
                columns: [[
                    {field:"id",edit:false,title:"编号",align:"center"},
                    {field:"user_company",edit:{
                                        type:'select',
                                        //数据来源地址
                                        //url:'user/getUser.htm',
                                        data:[{id:1,text:'lzx'},{id:2,text:'lsl'}],
                                        valueField:'id',
                                        textField:'text',
                                        onSelect:function(val,rec){
                                            console.log(val,rec);
                                        }
                    },title:"下拉框",align:"center",width:"200px"},
                    {field:"time",edit:{
                        type:'date',//日期
                        required:true,
                        click:function(){
                        }
                    },title:"时间",align:"center"},
                    {field:"name",title:"名字",align:"center"},
                    {field:"age",title:"年龄",align:"center"},
                    {field:"gender",title:"性别",align:"center",width:"200px",formatter:function(value,row,rowIndex){
                         if(value==1){
                          return '男';
                      }else if(value==2){
                          return '女';
                      }
                    },edit:{
                    type:'select',//下拉框
                    //数据来源地址
                    data:[{id:1,text:'男'},{id:2,text:'女'}],
                    valueField:'id',
                    textField:'text',
                    onSelect:function(val,rec){
                    console.log(val,rec);
                     }
                }}
              ]],
               onDblClickRow: function (row) {
                console.log(row.name)
              }
            });
            $('#addRowbtn').click(function(){
                var data = {};
                $('#table').bootstrapTable('prepend',data); 
            });

        });


        function removeRow(row){
            console.log(row);
        }
        function update(){
             var row = $('#table').bootstrapTable('getSelections')
             console.log(row)
             location.href="delete.action?uid="+row.uid
             var row = $('#dg').datagrid('reload');
    }

    function sava(){
        var row = $('#table').bootstrapTable("getSelections");
        if(row.length==0){
        alert("请选择一行");
        }else{
        console.log(row);
    }
   }

</script>
<body>
    <div id="myTabContent" class="tab-content">
       <!--可编辑表格-->
       <div class="tab-pane fade in active button" id="tab2">
          <button type="button" class="btn btn-success dropdown-toggle" id="addRowbtn">
           <span class="glyphicon glyphicon  glyphicon-plus" aria-hidden="true"></span>增加
         </button>
         <button type="button" class="btn btn-warning" onclick="javascript:update()">
              <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>修改
         </button>
         <button type="button" class="btn btn-info" onclick="javascript:sava()" id="sava">
              <span class=" glyphicon glyphicon-floppy-save" aria-hidden="true"></span>保存
         </button>
       </div>      
    </div>
 <div>
    <table class="table table-striped table-hover" id="table"></table>
 </div> 
  </body>
</html>

获取不到值 一直是undefined 很无奈

  • 写回答

1条回答

  • 一只会飞的白菜 2017-11-05 11:44
    关注

    后台返回的数据格式图片说明

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services