I am new to coffeescript and I have a coffee script code as
getProviderListDisplayValues:(domainId) ->
displayValues = []
$.ajax
contentType: 'application/json',
url: "/Services/ListProviders?domainid=#{domainId}",
success: (data) ->
for oneResponse in data
displayValues.push oneResponse.name
displayValues
which is compiled to
CounselorHome.prototype.getProviderListValues = function(domainId) {
var values;
values = [];
$.ajax({
contentType: 'application/json',
url: "/Services/ListProviders?domainid=" + domainId,
success: function(data) {
var oneResponse, _i, _len, _results;
_results = [];
for (_i = 0, _len = data.length; _i < _len; _i++) {
oneResponse = data[_i];
_results.push(values.push(oneResponse.id));
}
return _results;
}
});
return values;
};
I just want to push values to values[]
& displayValues[]
but why is the _results[]
array created? Does it hampers the browser efficiency? Is there any way removing such unnessary code? May be, by editing my coffee script.
EDIT : WORKING CONDITION
But when I put an alerting code as
$.ajax
contentType: 'application/json',
url: "/Services/ListProviders?domainid=#{domainId}",
success: (data) ->
for oneResponse in data
displayValues.push oneResponse.name
alert displayValues
displayValues
This code works and I can retrieve the required data.