- ABP Framework version: v3.3.2
- UI type: MVC
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:
I am trying to use Dynamic JavaScript API Client Proxies and use the values to populate the options in a Select dropdown. I am able to get the data but the problem i am facing is that I can not use the data outside the function scope. Inside the Proxies function, the data is available but when I want to use it outside the function then it is showing "undefined".
$typeId = data.items[i].achievementRegister.achievementTypeId; //selected value from a dropdown list
$achievementRegisterId = data.items[i].achievementRegister.id;
$achievementRegisterName = data.items[i].achievementRegister.fullName;
var code;
achievementTypeService.get($typeId)
.then(function (result) {
code = result.code;
//console.log(code); // showing the value
});
//creating an option for another select
temp = {
id: $achievementRegisterId,
text: '<span><b>' + code + '</b> ' + $achievementRegisterName + '</span>' // but not getting the value here
};
//adding the new option in the Select dropdown
newOption = new Option(temp.text, temp.id, false, false);
qualSelect.append(newOption).trigger('change');
I am not sure what I am doing wrong. I have tried to use the JS type variable ($code) and also declaring local variable (var code). But both of them gives the same problem.
Is there anyway to access the data outside the proxy functions?
2 Answer(s)
-
0
I think you are making a JS exception.
var code;
is defined and also being used before data is being fetched fromachievementTypeService.get($typeId)
and that's why it's undefined. this is kinda out of ABP scope but I suggest you to refactor this as belowvar createNewOption = function(newCode){ //creating an option for another select temp = { id: $achievementRegisterId, text: '<span><b>' + newCode + '</b> ' + $achievementRegisterName + '</span>' // but not getting the value here }; //adding the new option in the Select dropdown newOption = new Option(temp.text, temp.id, false, false); qualSelect.append(newOption).trigger('change'); } achievementTypeService.get($typeId) .then(function (result) { createNewOption(result.code); });
-
0
Hi Thanks for the response. It is working now. :)