Ext indicates that there are two ways to bind data to treeStore. One is the root attribute. The code is as follows: root: {expanded: true, text: & quot; myRoot & quot;, children: [{text: & quot; Child1
Ext indicates that there are two ways to bind data to treeStore. One isRootThe code is as follows:
root: { expanded: true, text: "My Root", children: [ { text: "Child 1", leaf: true }, { text: "Child 2", expanded: true, children: [ { text: "GrandChild", leaf: true } ] } ]}
In this way, only data in Tree format can be added, but if you want to add data in TreeGrid format, it will not work, so Pass.
The other isProxyMethod: there are two options for this method: Client and Server. Now I want to bind the data in json format. I must select Client, there are also three methods for the Client, of which only MemoryProxy is irrelevant to the browser, so select this method.
The Code is as follows:
//this is the model we will be using in the storeExt.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'}, {name: 'phone', type: 'string', mapping: 'phoneNumber'} ]});//this data does not line up to our model fields - the phone field is called phoneNumbervar data = { users: [ { id: 1, name: 'Ed Spencer', phoneNumber: '555 1234' }, { id: 2, name: 'Abe Elias', phoneNumber: '666 1234' } ]};//note how we set the 'root' in the reader to match the data structure abovevar store = Ext.create('Ext.data.Store', { autoLoad: true, model: 'User', data : data, proxy: { type: 'memory', reader: { type: 'json', root: 'users' } }});
If you use this code for testing, you cannot pass it because you add the store to the tree. an error will be reported in the panel, because the store format you created is not in TreeStore format. You need to modify this field and get the data to the proxy, because TreeStore does not have the data attribute, this is a problem with the Ext sample code. The modified result is:
var store = Ext.create('Ext.data.TreeStore', {autoLoad: true,model: 'Case',proxy: {type: 'memory',data: data,reader: {type: 'json',root: 'users'}}});