PDA

View Full Version : saving tree data



JonMoyles
12 Dec 2011, 9:49 PM
Hi,

I am trying to learn Ext and am trying to create an app that creates folders in a tree and saves them. So far the folders are being created successfully but I cannot save. I am getting a 'create' event to fire and it is getting a response from the correct .php file. I have not figured out how to pass data to the php though.

I call the create function like this;

store2.create(createOperation, createCallback(), this );

Also I do not know how to get data in the createCallback() function from the php.

Obviously something is escaping me but a lot of documentation I have been reading on Ext.data.Store is concerned with reading data, not saving it. The examples I looked at maybe abstracted the sync process a bit more than I understood. Anyway, I am confused.

Thanks in advance,
Jon

I include a more complete example below;



Ext.require(['*']);

var tree2 = null;
var store2 = null;

var createOperation = null;

Ext.onReady(function(){

Ext.define('BedOrBedGroup', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'parentBedGroupId']
});

createOperation = new Ext.data.Operation({
action: 'create'
});

store2 = Ext.create('Ext.data.TreeStore', {
model: 'BedOrBedGroup',
proxy: {
type: 'ajax',
url: 'main.php?action=saveBedGroup&control=Ajax&module=care',
autoSync: false,
api: {
create : 'main.php?action=saveBedGroup&control=Ajax&module=care'
},
reader: 'json'
},
root: {
text: 'Bed Groups',
id: 'src',
expanded: true,
children: []
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});

tree2 = Ext.create('Ext.tree.Panel', {
title: 'Bed Groups',
id: 'tree2',
width: 290,
height: 500,
store: store2,
style: {
float:'left'
},
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
appendOnly: true
}
},
renderTo: document.body
});
});

function addGroup(){
tree2.store.getRootNode().appendChild({id: bedGroupName, text: bedGroupName, leaf: false, children:[]});
store2.create(createOperation, createCallback(), this );
}

function createCallback(){
alert('createCallback()');
}

tobiu
13 Dec 2011, 3:33 AM
according to the api, the store has no method "create".

you can call:


store.sync();


or



store.getProxy().create();


sync fires 3 requests (create, update, destroy).

JonMoyles
13 Dec 2011, 2:54 PM
Thanks for replying. I changed to;


store2.getProxy().create(createOperation, createCallback(), this );

With exactly the same result. I am still not passing any parameters for the new item.

changing to;


store2.sync();

Gave me the error;

b is undefined

from ext-all.js (line 15) (firebug). As part of the update operation. I do have an update url defined I just omitted it from the example code for simplicity. That error seems to occur after the response is sent back from the update ajax call.

My problem is possibly that my data is passed into the tree as untyped JSON but my store specifies a model. However when I do not specify a model in my store I get the same result.

Does anyone have a good example of working with stores I can look at? I am afraid I did not understand how the data was being passed to the php to be saved in the tutorial 'Mapping a Grid to a MySQL table using Direct and PHP', so not that example please. Or just what I am doing wrong would be great too ;)

Thanks
Jon