【发布时间】:2014-12-17 08:51:57
【问题描述】:
我坚持将 javascript 对象绑定到淘汰可观察数组的方法。我正在使用 asp.net。我迷失了将 ajax 调用的响应数据分配给 javascript 对象。
我的 aspx 页面
<table id="gvActivityForm" class="test">
<th class="thdata">
TestSample
</th>
<tbody data-bind="foreach: arraytoadd">
<tr>
<td data-bind="text: testid"></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var TemplateFunction = function()
{
var self = this;
self.testid= ko.observable(0);
} //end
RealFunction = function ()
{
var self = this;
self.arraytoadd = ko.observableArray([]); //Adding an array
self.addevent = function()
{
self.arraytoadd.push(new TemplateFunction());
}
} //end of javascript object
objRealFunction = new realFunction();
ko.applyBindings(objRealFunction);
我正在通过 ajax 调用获取数据。
$.ajax({ //start ajax call for posting and getting the data back
type: 'POST',
url: 'PopupWebService.asmx/ReceiveandSendJobActivity',
data: JSON.stringify({item:obj}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
for(var i=0;i<response.d.length;i++)
{
TemplateFunction.testid= response.d[i].TestId; //My question is how do I assign the data .I am lost here
}
脚本>
【问题讨论】:
标签: asp.net knockout.js