-
19 May 2012 12:44 AM #1
Answered: extjs 4.1 tree add new node with server changes
Answered: extjs 4.1 tree add new node with server changes
In my application, the user can add some nodes to a tree node. The tree is connected to a store which has autoload and autosync true.The code to add a new node is this one:
Then the server will be notified and returns this json:Code:var window = button.up('window'); var form = window.getComponent('NodeForm').getForm(); var store = Ext.getStore('NodeStore'); var parentDir = window.parentDir; record = window.record ? window.record : NuageApp.model.Node.create(); if (form.isValid()) { form.updateRecord(record); if (window.record) { store.sync(); } else { parentDir.appendChild(record); } window.destroy(); }
The property text and icon changed server side but the store does not update the record.Code:{ "id": "4faccf93f597090d14000010/home/user/file", "text": "test file", "type": "file", "icon": "/images/icons/page.png", "expanded": true, "children": [] }
Code:Here is the configuration of the store: Ext.define('MyApp.store.NodeStore', { extend: 'Ext.data.TreeStore', requires: [ 'MyApp.model.Node' ], constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callParent([Ext.apply({ autoLoad: true, autoSync: true, storeId: 'MyJsonTreeStore1', model: 'MyApp.model.Node', proxy: { type: 'rest', reader: { type: 'json', idProperty: 'id' }, writer: { type: 'json', nameProperty: 'text' } }, sorters: { property: 'text' }, }, cfg)]); }, });
-
Best Answer Posted by vietits
Try to return json data as an array:
OrCode:[{ "id": "4faccf93f597090d14000010/home/user/file", "text": "test file", "type": "file", "icon": "/images/icons/page.png", "expanded": true, "children": [] }]
Code:{ "success": true, "children": [{ "id": "4faccf93f597090d14000010/home/user/file", "text": "test file", "type": "file", "icon": "/images/icons/page.png", "expanded": true, "children": [] }] }
-
21 May 2012 1:40 AM #2
-
22 May 2012 3:21 AM #3
I just make a git repository with my specific problem: https://github.com/cbou/extjs-nodejs-tree-panel-test
It would be nice if someone can take a look
-
27 May 2012 1:40 AM #4
I have the same problem. Did you resolve it? Here it is http://www.sencha.com/forum/showthread.php?208484-tree.Panel-drag-n-drop-on-fly-dropped-item-modification
I think it may be an issue with a difference between data model of treeView and a form. Is your form completely the same as a treeView node model?
-
27 May 2012 5:46 PM #5
Try to return json data as an array:
OrCode:[{ "id": "4faccf93f597090d14000010/home/user/file", "text": "test file", "type": "file", "icon": "/images/icons/page.png", "expanded": true, "children": [] }]
Code:{ "success": true, "children": [{ "id": "4faccf93f597090d14000010/home/user/file", "text": "test file", "type": "file", "icon": "/images/icons/page.png", "expanded": true, "children": [] }] }
-
30 May 2012 12:08 AM #6
Thanks vietits your second solution works for me.
I push a repository to make some tests: https://github.com/cbou/extjs-nodejs-tree-panel-test


Reply With Quote