我是如何在Kncokout中获得更改文本框的价值的 [英] Jow Do I Get The Value Of Changed Textbox In Kncokout

查看:50
本文介绍了我是如何在Kncokout中获得更改文本框的价值的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框。一个是雇员,另一个是工作时间。 employeename已预先填好。我必须为每个员工节省工作时间,我必须在javascript中获得工作时间并保存它们。我正在使用淘汰赛。每行都会有一个保存按钮。



如何在保存后从texbox获取更改后的工作时间?



UI(UserInterface)

I have to two textboxes. One is employeename and other is worked hours. employeename is already prefilled. I have to save work hours for each employee, I have to get the work hours in javascript and save them. I am using knockout. There will be a save button for each row.

How to get the changed worked hours from the texbox after they hit save?

UI(UserInterface)

<tbody data-bind="foreach: arraytoadd">
<tr>
    <td data-bind="text: employeename"></td>
    <td>&lt;input id="indynamicntendtime" data-bind="text: workedhours"/&gt;</td>  
    <td> &lt;input type="button" id="btnsave" value="save"/&gt; </td>                      
</tr>
</tbody>



Javascript


Javascript

Templatefunction = function()
{
   var self = this;
   self.employeename = ko.observavle("");
   self.workedhours = ko.observale("");
}

RealFunciton = function()
{
   ver self = this;
   self.arrarytoadd = ko.obeservablearray();
   self.addevent = function ()
   {
     self.arraytoadd.push( new Templatefunction);
   }
}



从Ajax获取值并分配


Getting the values from Ajax and assigning

 for(var i=0;i&lt;response.d.length;i++)&gt;
 {
     var x = new TemplateFunction();
     x.employeename(response.d[i].EmployeeName);
     x.workedhours(response.d[i].ActualContractorEndTime);
     jobactivityVM.arraytoadd.push(x);
 }


//TO DO  SAVE FUNCIONALITY. On every row save button click i have to get the corresponding workhours

  $(document).on("click", "[id*=btnsave]", function (e) {
      var x = new TemplateFunction();
      var contractorstarttime = Templatefunction["workedhours"]; //HOW TO GET THE CHANGED WORKED    HOURS .
      //start initialising the parameters needed for the ajax call
      var params = {};        
      params.workedhours=workedhours;

  });

推荐答案

document )。 on( click < span class =code-string> [id * = btnsave], function (e){
var x = new TemplateFunction();
var contractorstarttime = Templatefunction [ workinghours ]; // 如何获得更改的工作时间。
// 开始初始化ajax调用所需的参数
var params = {};
params.workedhours = workinghours;

});
(document).on("click", "[id*=btnsave]", function (e) { var x = new TemplateFunction(); var contractorstarttime = Templatefunction["workedhours"]; //HOW TO GET THE CHANGED WORKED HOURS . //start initialising the parameters needed for the ajax call var params = {}; params.workedhours=workedhours; });


最好使用表行上的点击绑定而不是jQuery点击处理程序。这将返回该行的数据。



接下来你就是workHours变量是一个函数。你应该把parentesis()放在它后面来获得价值。



http://knockoutjs.com/documentation/click-binding.html [ ^ ]
You're best off using the click binding on the table row instead of the jQuery click handler. This will return the data for that row.

And next to that you're workedHours variable is a function. You should put parentesis () behind it to get the value.

http://knockoutjs.com/documentation/click-binding.html[^]


这篇关于我是如何在Kncokout中获得更改文本框的价值的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆