asp.net mvc - Kendo UI access separately 2 array Json -
i have json returned mvc controller 2 arrays of data (1st - object, 2nd - primitive type string).
public actionresult categorieschartfiltereddata(string[] brands) { list<categorydata> categorydata = getcategorydata(); list<string> brandnames = getbrandnames(); return json( new { allbrandnames = brandnames, categoriesdata = categorydata } , jsonrequestbehavior.allowget); } i thought access individual arrays(or properties - here these brandnames , categorydata) via dot notation in data-bind: "source: ...", it's not working. tried [0] well, found somewhere, not sure if use right. i'm wrapping head around it, while it's basic, cannot trace example in docs or online.
<div id="container"> <select multiple="multiple" data-role="multiselect" data-bind="source: datacomparisons.allbrandnames"></select> <div data-role="chart" data-bind="source: datacomparisons.categoriesdata" data-series-defaults="{type: 'column'}" data-series="[{field: 'coverage'}]"></div> </div> i'm using viewmodel below:
<script type="text/javascript"> var viewmodel = kendo.observable({ autosync: true, datacomparisons: new kendo.data.datasource({ transport: { read: { url: "/dashboard/categorieschartfiltereddata", datatype: "json" } }, }) }); kendo.bind($("#container"), viewmodel); </script>
kendo.data.datasource not designed handle multiple data arrays. split in separate requests or make custom manual ajax request , fill viewmodel
update
1.separate datasources (two separate mvc actions categoriesdata , brandnames , binddings data-bind="source: categoriesdata , data-bind="source: brandnames):
var viewmodel = kendo.observable({ autosync: true, categoriesdata: new kendo.data.datasource({ transport: { read: { url: "/dashboard/categoriesdata", datatype: "json" } }, }), brandnames: new kendo.data.datasource({ transport: { read: { url: "/dashboard/brandnames", datatype: "json" } }, }) }); 2.external ajax request:
$.ajax({ type:'post', //or 'get' url:'/dashboard/categorieschartfiltereddata', success:function(data){ var viewmodel = kendo.observable({ autosync: true, datacomparisons: data }); kendo.bind($("#container"), viewmodel); } })
Comments
Post a Comment