我有这个从实体名声中获取数据的视图模型。我能够成功地将它从 JSON 转换为数组,但它是不可观察的。我尝试创建一个具有可观察属性的模型,然后为每个模型填充一个,但这似乎不起作用。我还尝试使用 ko.mapping.fromJSON,它在服务端似乎工作正常,但在视图上总是空的。
function(logger, system, router, employeeService) {
var EmployeeDetails = ko.observableArray([]);
Activate Function -
var activate = function () {
return GetEmployeeDetails(),GetTermList();
};
var vm = {
activate: activate,
FindID: ko.observable(),
EmployeeDetails: EmployeeDetails
}
};
function GetEmployeeDetails() {
return employeeService.getemployeeDetails(EmployeeDetails);
}
//这是我的employeeService类中的函数
var getEmployeedetails = function(employeeDetailsOb) {
var jsonfromServer;
$.ajax({
type: "POST",
dataType: "json",
url: "/api/employee/getAllDetails/",
data: '{}',
success: function(data) {
jsonfromServer = $.parseJSON(data);
},
error:
{ //error stuff})
Return employeeDetailsOb(jsonFromServer);
}