Rename and Insert erro TreeStore ExtJS 4.1.1
Question
Good Evening guys,
When I update the method it does not save all model items like "tipoNo" and "pai". Someone know what i can do ?
Request Payload
This is the information sent in the request.
{"parentId":1,"nome":"qwfqwfqw"}
Model:
Fields in the my model.
fields : [ {
name : 'id',
type : 'long'
},{
name : 'pai',
type : 'long'
}, {
name : 'nome',
type : 'string'
}, {
name : 'tipoNo',
type : 'string'
}, {
name : 'leaf',
type : 'boolean',
convert : function(value, record) {
var no = record.get('tipoNo');
return (no == "CLIENTE" ? true : false);
}
} ],
Proxy
Proxy to requisite information on the server.
proxy : {
type : 'rest',
url : Webapp.link('node'),
reader : {
type : 'json',
root : 'nodes',
idProperty : 'id'
},
writer : {
type : 'json',
writeAllFields : false
}
}
Controller Method
/**
* Rename
*
* @param {Ext.grid.plugin.CellEditing} editor
* @param {Object} e
*/
updateList : function (editor, e) {
var node = e.record;
node.save({
success: function(list, operation) {
console.log("updated");
},
failure: function(list, operation) {
var error = operation.getError(),
msg = Ext.isObject(error) ? error.status + ' ' + error.statusText : error;
Ext.MessageBox.show({
title: 'Notificação',
msg: msg,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
});
},
Solution 2
Solution in this case:
/**
* Executa a edição
*
* @param {Ext.grid.plugin.CellEditing} editor
* @param {Object} e
*/
updateList : function (editor, e) {
var node = e.record;
var me = this;
var nodeTree = me.getNodeTree();
var method = (node.data.id !== undefined ? 'PUT' : 'POST');
var post = {
id: (node.data.id !== undefined ? null : node.data.id),
nome: node.data.nome,
pai: (node.data.parentId == -1 ? null : node.data.pai),
tipoNo: node.data.tipoNo
};
Ext.Ajax.request({
url: Webapp.link("node"),
headers: { 'Content-Type': 'application/json' },
jsonData: post,
method: method,
success: function(response){
var text = response.responseText;
console.log(text);
nodeTree.refreshView();
}
});
},
OTHER TIPS
Take a look at your proxy configuration. Your JSON writer has the writeAllFields
property set to false. From the Ext.data.writer.Json documentation:
True to write all fields from the record to the server.
If set to false it will only send the fields that were modified.
So any fields that have not been touched will not be sent back to the server. If you want all properties to be sent to the server, set writeAllFields
to true (or just remove it, since true is the default) and try again.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow