使用jquery模板插件时出现问题

时间:2012-04-04 09:54:11

标签: jquery jquery-ui-dialog jquery-templates

页面上有一个网格。当我点击行 - 项目编辑表单时,对话框中显示的项目数据(jquery对话框ui插件)。 问题是在单击对话框“保存”按钮后,使用新用户输入从html获取数据项。 这是我的代码:

$('#OutLookAccountsGrid').on('click', 'span.btnOutlookAccountEdit', function () {


    //getting data from grid row
    var account = $(this).tmplItem().data;
    //populating edit template with data
    var tbl = $('#outlookaccountEditFormTmpl').tmpl(account);

    //displaying edit form inside dialog
    tbl.dialog({
        modal: true,
        width: 400,
        buttons: {
            "Yes": function () {
                var $this = $(this);

                //PROBLEM!!! PROBLEM!!! PROBLEM!!!
                //want to get values from user, but instead getting old values
                //populated from grid row
                var data = $.tmplItem(this).data;

                //...
                //want to send tmplItem with new values throught ajax as data param
                //...

          }
        }
     })//end of dialog

})

是否可以使用新值获取对象?

1 个答案:

答案 0 :(得分:0)

这个问题的答案:jquery模板只能以一种方式将数据与html绑定:从数据到html,因此输入的变化对数据没有影响。 (有一些名为jquery.datalink的插件试图将对象链接到模板,但据我所知它在当前版本的teplate插件中不起作用) 因此,在用户将值插入输入后获取更改数据的唯一途径是:

   $.tmplItem(this).data["UserName"] = $this.find('input.outlusernm').val();

将在数据对象中进行更改