On my webpage, I am displaying product data that is being called in the form of a JSON object in the JavaScript file:
_loadAll: function (callback) {
$.ajax({
'type': 'GET',
'timeout': 5000,
'cache': false,
'dataType': 'json',
'url': Application.ProductURL + 'Series/Load/All',
success: function (response) {
if (response && callback) {
callback(response);
}
},
error: function (request, errorText, errorCode) {
}
});
}
(Note: I inherited this project from someone else and I'm still trying to understand how it functions)
I found the ProductURL which is defined like this in C# :
public Stream LoadProduct(string productNumber)
{
var product = new JSONObjects.JProduct(productNumber);
return SerializationHelper.Streamify(product);
}
public Stream LoadAllSeries()
{
IProductSeriesCollection series = new ProductSeriesCollection();
series.LoadAll();
return SerializationHelper.Streamify(series);
}
The JProduct class is located in another .cs file:
public class JProduct: IProduct
{
public int Id { get; set; }
public int SeriesId { get; set; }
public string Name { get; set; }
public void Load(string productNumber)
{
_product = new ProductProxy(productNumber);
Id = _product.Id;
SeriesId = _product.SeriesId;
Name = _product.Name;
}
My question now is: The products are currently displayed sorted by ID, which seems to be the default. However, I need them to be sorted by Name. Can I achieve this within the JavaScript file? Since I'm new to working with JSONs, any suggestions on how to sort the products by Name would be greatly appreciated!