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
    });
有帮助吗?

解决方案

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());
});

其他提示

Well you can do this easily, try using this:

$.each(fetecheddata(), function (i, val) {
    alert(val.name());//This does not work
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top