这个员工变量我从本地存储中获取它。
我的HTML
<table id='exampletable' align="center">
<thead>
<tr>
<th></th>
<th>TicketNumber</th>
<th>TargetDate</th>
<th>SiteID</th>
<th>ServiceType</th>
<th>AssignedTOEmpName</th>
<th>TicketStatus</th>
<th>complaintDescription</th>
<th>ReportingPersonPhoneNumber</th>
</tr>
</thead>
<tbody data-bind="foreach: addresses">
<tr >
<td><a href='newticket.html'><img data-bind="click: $parent.SelectTicket" src='./images/edit.png' border='0'/></a></td>
<td data-bind="text: TicketNumber"></td>
<td data-bind="text: TargetDate"></td>
<td data-bind="text: SiteID"></td>
<td data-bind="text: ServiceType"></td>
<td data-bind="text: AssignedTOEmpName"></td>
<td data-bind="text: TicketStatus"></td>
<td data-bind="text: complaintDescription"></td>
<td data-bind="text: ReportingPersonPhoneNumber"></td>
</tr>
</tbody>
</table>
脚本:
var employee = getjson("emp");
function ViewModel() {
var self = this;
self.addresses = ko.observableArray([]);
ko.mapping.fromJS(employee.tasks, {}, self.addresses);
}
var viewModel = new ViewModel();
//function binding work order details to view
$(document).ready(function () {
ko.applyBindings(viewModel);
});
数据
employee = {
"querySucess": true,
"SelfEmployeeView": {
"FirstName": "Binesh ",
"LastName": "Dadiya",
"CompanyID": "xyz",
"ReportingManager": {
"FirstName": "Mohammad",
"LastName": "Saeef"
}
},
"tasks": [
{
"fetchedDateandtime": "Apr 22, 2015 2:16:48 PM",
"isSupervisor": false,
"TicketNumber": "MyTT876",
"TargetDate": "Aug 29, 2014",
"CustomerName": "PQR",
"SiteID": "STID",
"ServiceType": "PM",
"GeneralIssuesList": "EBCNC",
"TicketStatus": "CU",
"ReportingPersonName": "Kashim Khan",
"ReportingPersonPhoneNumber": "790"
},
{
"fetchedDateandtime": "Apr 22, 2015 2:16:48 PM",
"isSupervisor": false,
"TicketNumber": "MyTT876",
"TargetDate": "Aug 29, 2014",
"CustomerName": "PQR",
"SiteID": "STID",
"ServiceType": "PM",
"GeneralIssuesList": "EBCNC",
"TicketStatus": "CU",
"ReportingPersonName": "Kashim Khan",
"ReportingPersonPhoneNumber": "790"
},
{
"fetchedDateandtime": "Apr 22, 2015 2:16:48 PM",
"isSupervisor": false,
"TicketNumber": "MyTT876",
"TargetDate": "Aug 29, 2014",
"CustomerName": "PQR",
"SiteID": "STID",
"ServiceType": "PM",
"GeneralIssuesList": "EBCNC",
"TicketStatus": "CU",
"ReportingPersonName": "Kashim Khan",
"ReportingPersonPhoneNumber": "790"
},
{
"fetchedDateandtime": "Apr 22, 2015 2:16:48 PM",
"isSupervisor": false,
"TicketNumber": "MyTT876",
"TargetDate": "Aug 29, 2014",
"CustomerName": "PQR",
"SiteID": "STID",
"ServiceType": "PM",
"GeneralIssuesList": "EBCNC",
"TicketStatus": "CU",
"ReportingPersonName": "Kashim Khan",
"ReportingPersonPhoneNumber": "790"
}
]
}
答案 0 :(得分:0)
正如我所看到的,数据缺少属性:
AssignedTOEmpName
complaintDescription
当您添加空值时,您将使其正常工作。
{
"fetchedDateandtime": "Apr 22, 2015 2:16:48 PM",
"isSupervisor": false,
"TicketNumber": "MyTT876",
"TargetDate": "Aug 29, 2014",
"CustomerName": "PQR",
"SiteID": "STID",
"ServiceType": "PM",
"GeneralIssuesList": "EBCNC",
"TicketStatus": "CU",
"AssignedTOEmpName": '',
"complaintDescription" :'',
"ReportingPersonName": "Kashim Khan",
"ReportingPersonPhoneNumber": "790"
},