2012-04-04 70 views
0

我在頁面上有一個網格。當我點擊行 - 項目數據顯示在對話框(jQuery的對話框UI插件)內的項目數據編輯窗體。 問題是在點擊對話框「保存」按鈕後,用新的用戶輸入從html中獲取數據項。 這裏是我的代碼:與jQuery模板插件的問題

$('#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 

}) 

是有可能得到的對象與新的價值?

回答

0

這個問題的答案:jquery模板只能以一種方式將數據綁定到html上:從數據到html,因此輸入更改對數據沒有任何影響。 (有一些名爲jquery.datalink的插件試圖將對象鏈接到模板,但據我所知它不適用於當前版本的teplate插件) 因此,在用戶插入輸入值之後獲取更改數據的唯一方法是:

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

這將使數據項目發生變化