$scope.Edit = function (id) {
console.log("edit id : " + id);
$scope.Employee = {};
$scope.eid = id;
var data = JSON.stringify({empid: $scope.eid});
var url = "/services/EmployeeService.asmx/EditEmployee";
$http.post(url, data).then(function (response) {
$scope.Employee = response.data;
console.log($scope.Employee.fname);
console.log($scope.Employee);
var mydata = jQuery.parseJSON(JSON.stringify(response.data));
console.log(mydata);
}, function (response) {
console.log(response.status);
console.log(response.statusText);
});
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string EditEmployee(int empid)
{
Employee employee = new Employee();
if (emplist.Count > 0)
{
foreach (Employee emp in emplist)
{
if (emp.empId == empid)
{
employee.empId = empid;
employee.fname = emp.fname;
employee.city = emp.city;
employee.mobile = emp.mobile;
employee.country = emp.country;
break;
}
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
Context.Response.ContentType = "application/json";
List<Employee> elist = new List<Employee>();
elist.Add(employee);
return new JavaScriptSerializer().Serialize(elist);
}
這是我從響應
對象 d的了: 「[{」 EMPID「: 103,「fname」:「sujith」,「city」:「trichy」,「mobile」:「56456456」,「country」:「India」}]「 proto:Object
我該如何解析角度js對象。我要像這樣訪問:$scop.Employee.empId,$scope.Employee.fname
感謝&問候 阿倫
嗨Vikas Thakur,感謝您的幫助,但它仍然返回undefined, –
$ scope.Employee = response.data.d [0]; console.log($ scope.Employee.fname); // return undefined –
console.log(response.data.d); //返回[{「empId」:103,「fname」:「sujith」,「city」:「trichy」,「mobile」:「56456456」,「country」:「India」}] console.log(response .data.d [0]); //返回[ –