Search code examples
google-app-maker

Appmaker reload value


I have a value calculated in window.Sum and I need to display it in label1. Window.Sum is calculated when datasource is filtered and label1 text is set to window.Sum. I log the value of window.Sum and it is correct. How do I force the label1 to display the value everytime the window.Sum is updated?


Solution

  • Let's suppose that the function to calculate the sum you are using is this one:

    function calculateSum(){
    
        /* do your stuff right here */
        var sum = x+y;
    }
    

    All you need to do is to pass the label widget to the function and update the widget text property once you get the sum value, like this:

    function calculateSum(labelWidget){
    
        /* do your stuff right here */
        var sum = x+y;
        labelWidget.text = sum;
    }
    

    Then you just invoke your function passing the labelWidget like this:

    var labelWidget = app.pathToWhereYourLabelWidgetIsLocated;
    calculateSum(labelWidget);
    

    Since your question is pretty vague, this is the best I can do to answer your question. Please consult the official documentation for widgets data binding and widgets api to further understand how to achieve this type of things. Hope it helps!