I am trying to create a dynamic table that is being built based on the value of a search text box. The Table will have probably 6 columns of 20(max) rows.
My problem is I can't figure out how to return the data from the web-service to the JS function in a way that will allow me to extract the data that I need.
Here is the web-service method I have currently:
[WebMethod]
public v_EMU_AIR_AIR[] GetCompletionList(string prefixText)
{
NeoDataContext dataContext = new NeoDataContext();
var results = from a in dataContext.GetTable<v_EMU_AIR_AIR>()
where a.Report_Date_ID.StartsWith(prefixText) ||
a.Item_Description.Contains(prefixText) ||
a.Drw_Nbr.StartsWith(prefixText)
select a;
return results.ToArray<v_EMU_AIR_AIR>();
}
This will return an Array my objects, but in my javascript:
populateTable:function(returnList) {
var length = returnList.childNodes[0].childNodes.length
for(var i=0; i<length; i++) {
开发者_开发问答 var textValue = returnList.childNodes[0].childNodes[i].textContent
$("<tr><td>" + textValue + "</td></tr>").insertAfter(this.tblResults[0].childNodes[1]);
}
}
All I can produce is a dump of the entire Object and can't pull out the specific fields that I need.
I would serialize your object using Javascript Object Notation (JSON).
Unfortunately, this feature isn't built in to the .NET framework, so you'll need to write the code yourself.
Fortunately, most of it is already done for you. Check out this link or this link for more information.
In your javascript, you can retreive the JSON object with jquery (documentation) and access the values of your properties like you would in C#
$(document).ready(function() {
$.getJSON("http://url.to.webservice.com/", function(jsonObj) {
alert(jsonObj.property);
});
});
精彩评论