Question

I have a viewmodel that looks like the one below. The data is gotten from a database and I need to create a charts and tables from this data, not in the view but in the script. How can I access the fetched data?

I guess this can be done through the function attached but how do I do that?

var vm = {
    activate: activate,
    data: fetecheddata,
    attached: attached
};

function attached(view, parent){
}

EDIT I am able to execute fetecheddata().length but how will I get the properties of the attributes in a loop. Something like

$.each(fetecheddata, function (i, val) {
        alert(val.name);//This does not work
    });
Was it helpful?

Solution

If fetchdata is an observable Array, then you have to loop through the array using knockout utility function like:

ko.utils.arrayForEach(fetecheddata(), function(item) {
  alert(item.name());
});

OTHER TIPS

Well you can do this easily, try using this:

$.each(fetecheddata(), function (i, val) {
    alert(val.name());//This does not work
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top