Skip to content Skip to sidebar Skip to footer

Observablearray Not Updating The Ui

I am facing a problem that the UI only updates with correct data after a refresh of the page. I am coming from here observableArray is not defined My JS Code: define( ['knockou

Solution 1:

Create the array once in onLoad, and then just update it. Don't keep creating it each time.

define(
    ['knockout'],
    function (ko) {
        "use strict";
        return {
            onLoad: function (widget) {
                widget.myKoObservableArray = ko.observableArray();
                widget.getDetails= function (prod) {
                    var abc = prod.DetailsNumbers();
                    console.log(abc);
                    var someArray= [];
                    someArray= abc.split(',');
                    //console.log(someArray);

                    // empty the array
                    widget.myKoObservableArray([]);

                    for (var i = 0; i < someArray.length; i++) {
                        var temp = {
                            "prodName": ko.observable(someArray[i])
                        };
                        widget.myKoObservableArray.push(temp);

                    }
                    console.log(widget.myKoObservableArray());
                };
            }
        }
    }
);

Post a Comment for "Observablearray Not Updating The Ui"