2014-06-12 2 views
0

"undefined"인쇄가 3 번 (적절한 횟수) 인쇄됩니다. 찾은 입력에 대해 데이터 바인딩 값을 얻으려면 어떻게해야합니까?jquery로 데이터 속성 값을 인쇄하십시오.

function DataBindForEdit(dataTag, controller, action) { 
    // get the inputs that will be sent to the controller 
    var dataBoundControls = $('[data-bind="' + dataTag + '"] [data-bind]'); 

    // loop over each element 
    dataBoundControls.each(function() { 
     var self = $(this); 

     // for now just print out the value of the data-bind attribute 
     alert(self.data("data-bind")); 
    }); 
} 

@section Scripts{ 
    <script> 
     $(function() { 

      $("#btnSave").click(function(){ 
       DataBindForEdit("Customer", "Index", "CreateCustomers"); 
      }); 
     }); 
    </script> 
} 

<form data-bind="Customer"> 
    Name: <input type="text" data-bind="Name" data-bind-type="text" /> 
    Birthday: <input type="text" data-bind="Birthday" data-bind-type="text" /> 
    Address: <input type="text" data-bind="Address" data-bind-type="text" /> 
    <input type="submit" value="Save" id="btnSave" /> 
</form> 

답변

2

data-을 포함하면 안됩니다. 그것은이어야한다 :

self.data("bind") 
+0

나는 아주 가까웠다. :) Thx는 효과가있었습니다. – user441521

+0

정말 대단히 닫습니다 !! – PeterKA

관련 문제