I'm writing Telerik platform hybrid app. I want to write a function which returns a number from Everlive cloud. Here's my code.
function getSector(){
var result = 0;
var data = el.data('csector');
data.get()
.then(function (data) {
var obj = JSON.parse(JSON.stringify(data));
//alert(obj.result[0].current);
result = obj.result[0].current;
},
function (error) {
alert(JSON.stringify(error));
});
return result;}
Problem is that I can't return value. It always returns 0. Seems like result can't be changed from nested function? Alert works great. Please help. Documentation
If you are calling your function from somewhere in JS and other than in your markup directly (data binding), then you may need to implement promises through jQuery, angular or some other library. Here is jQuery's implementation: https://api.jquery.com/promise/
If you are calling the function through data binding then your function should modify a property on your model and then your markup should be bound to that property. Without more information about your project it is hard to answer definitively.