javascript - Getting original data from kendo UI DataSource -


in kendo ui documentation datasource component, states data function used data items data source.

however states if data source bound javascript array (via data option) data method return items of array. every item array wrapped in kendo.data.observableobject or kendo.data.model.

how can retrieve original unwrapped data items (i.e. having same reference) passed data source?

i ask because i'm using kendo ui treeview control , in event handlers (e.g. check event) want update original data item tree node based on custom logic.

update

for example here simple treeview having single node (of course in realistic scenario tree contain many nodes) . when checking node want reference original data item checked node. this.dataitem(e.node) not return original data item log statement outputs false.

<div id="treeview"></div> <script>   var mydata =  [     { text: "foo", checked: false}   ]; $("#treeview").kendotreeview({   checkboxes: true,   datasource: mydata,   check: function(e) {         console.log(this.dataitem(e.node) == mydata[0]); //i want output true   } }); </script> 

if understand question correctly, can records independently referencing data source , using .at(x) function, x equals whatever record of data source attempting access. first.

var thedata = yourdatasource.at(0); 

to update it, use .set , .sync.

thedata.set('userfirstname', 'joe'); thedata.set('useraveragetime', 10); yourdatasource.sync(); 

using .set() handy because if store updates iterable collection, can run through them.

$.each(updatedvars, function(key, element) {    thedata.set(key, element); }); yourdatasource.sync(); 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -