I'm iterating through a set of json data which carries results of a few database tables. Amongst other data I have a RateTable ...erm... table, and a Resources table. The RateTable has a property name ResourceId which links to the Resources record.
So, I'm iterating through my RateTable and I need to reference my Resource record and use it by copying it into it's own variable. Here is what I have so far:
if (data)
{
var rs = data.Resources;
$.each(data.RateTables, function(i,item){
if (item.RateTableTypeId == 91)
{
var r = getresource(item.SupplierResourceId, rs)
if (r)
customer_options += '<option value="' + r.ResourceId + '">' + r.Name + '<\/option>';
}
else if (item.RateTableTypeId == 92)
{
var r = getresource(item.CustomerResourceId, rs)
if (r)
supplier_options += '<option value="' + r.ResourceId + '">' + r.Name + '<\/option>';
}
});
$(".ddl-customer").html(customer_options);
$(".ddl-supplier").html(supplier_options);
}
function getresource(id, items)
{
$.each(items, function(i,item){
if (item.ResourceId == id)
return $.extend(true, {}, item);
});
}
The problem I have is that getresource isn't returning a copy of my Resource item in the variable r. Why?
Sorry I can't post some of the json data, it's absolutely huge, which is why we are leaving the referencing to the client side to cut down on the data payload. I'm hoping there is enough to help someone see what I'm trying to do.
Lloyd