残缺丶
2015-04-29 03:01
采纳率: 56%
浏览 10.1k
已采纳

easyui dialog点修改按钮将当前修改行的数据赋值给修改窗口的文本框?

我需要点击修改按钮时,将我当前选中行的数据对应的赋值给dialog弹出的修改窗口,看一下代码吧

  {
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                var row = $('#tab').datagrid('getSelected');
                if (row == null)
                {
                    $.messager.alert("系统提示", "请选择您要修改的数据!");
                    return;
                }
                if (row)
                {
                    $("#txtLoginId").val(row.LoginId);
                    $("#txtLoginPwd").val(row.LoginPwd);
                    $("#txtUserStateId").val(row.UserStateId);
                    $("#txtTeacherName").val(row.TeacherName);
                    $('#txtSex').val(row.Sex);
                    $('#txtBirthday').val(row.Birthday.datebox('getValue'));
                }
                $("#divadd").show();
                $("#divadd").dialog({
                    title: '修改',
                    width: 300,
                    height: 300,
                    closed: false,
                    cache: false,
                    modal: true,
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            var teacherid = row.teacherid;
                            var loginid = $("#txtLoginId").val();
                            var LoginPwd = $("#txtLoginPwd").val();
                            var UserStateId = $("#txtUserStateId").val();
                            var TeacherName = $("#txtTeacherName").val();
                            var Sex = $('#txtSex').datebox('getValue');
                            var Birthday = $('#txtBirthday').datebox('getValue');
                            $.ajax({
                                type:"post",
                                url: "Handler.ashx?type=2&TeacherId="+teacherid+"&loginId=" + loginid + "&LoginPwd=" + LoginPwd + "&UserStateId=" + UserStateId + "&TeacherName=" + TeacherName + "&Sex=" + Sex + "&Birthday=" + Birthday,
                                success: function (data) {
                                    if (data == "ok") {
                                        $.messager.alert("系统提示", "数据修改成功!");
                                        showDate();
                                        $('#divadd').dialog('close');
                                    }
                                    else {
                                        $.messager.alert("系统提示", "数据修改失败!");
                                        return false;
                                    }
                                }
                            })
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cut',
                        handler: function () {
                            $('#divadd').dialog('close');
                            $("input").val('');
                        }
                    }]
                })
            }

没有赋值成功,求赐教!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 已采纳

    $('#txtBirthday').val(row.Birthday.datebox('getValue'));

    你这个有问题。。row.Birthday不是easyui的datebox,你的Birthday是什么内容,不是对象就直接下面的,是json对象获取属性值

     $('#txtBirthday').val(row.Birthday);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • danielinbiti 2015-04-29 03:29

    先跟踪一下看看row有没有值

    评论
    解决 无用
    打赏 举报
  • 残缺丶 2015-04-29 05:59

    这是我的html代码

     <body>
        <form id="form1" runat="server">
        <div>
        <table id="tab">
            <thead>
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th data-options="field:'TeacherId',width:100">编号</th>
                    <th data-options="field:'LoginId',width:100">登录名</th>
                    <th data-options="field:'LoginPwd',width:100">密码</th>
                    <th data-options="field:'UserStateId',width:100">状态</th>
                    <th data-options="field:'TeacherName',width:100">姓名</th>
                    <th data-options="field:'Sex',width:100">性别</th>
                    <th data-options="field:'Birthday',width:100,formatter: jointimeconvert ">生日</th>
                </tr>
            </thead>
        </table>
        </div>
            <div id="divadd"><br />
                帐号:<input class="easyui-textbox" id="txtLoginId" style="width:200px" /><br /><br />
                密码:<input class="easyui-textbox" id="txtLoginPwd" style="width:200px"/><br /><br />
                状态:<input class="easyui-textbox" id="txtUserStateId" style="width:200px"/><br /><br />
                姓名:<input class="easyui-textbox" id="txtTeacherName" style="width:200px"/><br /><br />
                性别:<input class="easyui-combo" id="txtSex" style="width:200px"/><br /><br />
                生日:<input class="easyui-datebox" id="txtBirthday" style="width:200px"/><br />
            </div>
            <div id="sp" style="height:30px">
                <input type="radio" name="ra" value="男"/><span>男</span><br/>
                <input type="radio" name="ra" value="女"/><span>女</span><br/>
            </div>
        </form>
    </body>
    

    这是我的js代码

     <script>
            var toolbar = [{
                text: '添加',
                iconCls: 'icon-add',
                handler: function () {
                    $("#divadd").show();
                    $("#divadd").dialog({
                        title: '添加',
                        width: 300,
                        height: 300,
                        closed: false,
                        cache: false,
                        modal: true,
                        buttons:[{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                var loginid = $("#txtLoginId").val();
                                var LoginPwd = $("#txtLoginPwd").val();
                                var UserStateId = $("#txtUserStateId").val();
                                var TeacherName = $("#txtTeacherName").val();
                                var Sex = $('#txtSex').datebox('getValue');
                                var Birthday = $('#txtBirthday').datebox('getValue');
                                $.ajax({
                                    url: "Handler.ashx?type=2&loginId=" + loginid + "&LoginPwd=" + LoginPwd + "&UserStateId=" + UserStateId + "&TeacherName=" + TeacherName + "&Sex=" + Sex + "&Birthday=" + Birthday,
                                    success: function (data) {
                                        if (data == "ok") {
                                            $.messager.alert("系统提示", "数据添加成功!");
                                            showDate();
                                            $('#divadd').dialog('close');
                                            $("input").val('');
                                        }
                                        else {
                                            $.messager.alert("系统提示", "数据添加成功!");
                                            return false;
                                        }
                                    }
                                })
                            }
                        },{
                            text: '关闭',
                            iconCls: 'icon-cut',
                            handler: function () {
                                $('#divadd').dialog('close');
                                $("input").val('');
                            }
                        }]
                    })
                }
            }, '-', {
                text: '删除',
                iconCls: 'icon-cut',
                handler: function () {
                    var row = $('#tab').datagrid('getSelected');
                    if (row) {
                        $.messager.confirm("提示", "你确定要删除吗?", function (r) {
                            if (r) {
                                $.ajax({
                                    url: "Handler.ashx?type=3&ID=" + row.TeacherId,
                                    success: function (data) {
                                        if (data == "ok") {
                                            $.messager.alert("系统提示", "数据删除成功!");
                                            showDate();
                                        }
                                        else {
                                            $.messager.alert("系统提示", "数据删除失败!");
                                        }
                                    }
                                })
                            }
                        })
                    }
                }
            }, '-', {
                text: '修改',
                iconCls: 'icon-edit',
                handler: function () {
                    var row = $('#tab').datagrid('getSelected');
                    if (row == null)
                    {
                        $.messager.alert("系统提示", "请选择您要修改的数据!");
                        return;
                    }
                    $("#divadd").show();
                    if (row)
                    {
                        $("#divadd").dialog({
                            title: '修改',
                            width: 300,
                            height: 300,
                            closed: false,
                            cache: false,
                            modal: true,
                            buttons: [{
                                text: '保存',
                                iconCls: 'icon-save',
                                handler: function () {
                                    var teacherid = row.TeacherId;
                                    var loginid = $("#txtLoginId").val();
                                    var LoginPwd = $("#txtLoginPwd").val();
                                    var UserStateId = $("#txtUserStateId").val();
                                    var TeacherName = $("#txtTeacherName").val();
                                    var Sex = $('#txtSex').datebox('getValue');
                                    var Birthday = $('#txtBirthday').datebox('getValue');
                                    $.ajax({
                                        type: "post",
                                        url: "Handler.ashx?type=4&TeacherId=" + teacherid + "&loginId=" + loginid + "&LoginPwd=" + LoginPwd + "&UserStateId=" + UserStateId + "&TeacherName=" + TeacherName + "&Sex=" + Sex + "&Birthday=" + Birthday,
                                        success: function (data) {
                                            if (data == "ok") {
                                                $.messager.alert("系统提示", "数据修改成功!");
                                                //showDate();
                                                $('#tab').datagrid('reload');
    
                                                $('#divadd').dialog('close');
                                            }
                                            else {
                                                $.messager.alert("系统提示", "数据修改失败!");
                                                return false;
                                            }
                                        }
                                    })
                                }
                            }, {
                                text: '关闭',
                                iconCls: 'icon-cut',
                                handler: function () {
                                    $('#divadd').dialog('close');
                                    // $("input").val('');
                                }
                            }]
                        })
                        $("#txtLoginId").val(row.LoginId);
                        $("#txtLoginPwd").val(row.LoginPwd);
                        $("#txtUserStateId").val(row.UserStateId);
                        $("#txtTeacherName").val(row.TeacherName);
                        $('#txtSex').val(row.Sex);
                        $('#txtBirthday').val(row.Birthday);
                    }
                }
            }];
            jQuery(function () {
                showDate();
    
            });
            function jointimeconvert(value, row, index) {
                return new Date(jsonDateFormat(value)).toLocaleDateString();
            }
            function showDate()
            {
                $('#txtSex').combo({
                    multiple: true,
                    editable: false
                });
                $('#sp').appendTo($('#txtSex').combo('panel'));
                $('#sp input').click(function () {
                    var v = $(this).val();
                    var s = $(this).next('span').text();
                    $('#txtSex').combo('setValue', v).combo('setText', s).combo('hidePanel');
                });
                $("#divadd").hide();
                $("#tab").datagrid({
                    url: "Handler.ashx?type=1",
                    width: 720,
                    fitColumns: true,
                    striped: true,
                    singleSelect: true,
                    rownumbers: true,
                    toolbar: toolbar,
                    pagination: true,
                    pageSize: 10,
                    pageList:[5,10,20,50],
                    onLoadSuccess: function (data) {
                        // $('#tab').datagrid('reload');
                    }
                })
            }
        </script>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题