My store function was working efficiently on extjs 6.0, but when migrated to extjs 6.7 its showing error
var store = Ext.create('Ext.data.Store',{
model: 'User',
proxy: {
type: 'ajax',
url : '../ROOT/customHeader/configs/customHeaderConfig.json',
reader:
{
type: 'json',
rootProperty: "custom"
}
},
autoLoad:true,
listeners : {
load : function(thisObj, records){
var logo_src = records[0].get("viewer_logo_src");
panObj.getComponent('header_toolbar').getComponent('headerLogo').setSrc(logo_src);
}
}
});
Related
Store callback as follows:
var store = new Ext.create("Ext.data.TreeStore", {
model: "DeptModel",
proxy: {
type: 'ajax',
url: 'jsonWebCommMenuOp_getMenus?PID=0',
reader: 'json'
},
autoload: true
});
store.load({
callback: function(records, options, success) {
var jsonStr = Ext.JSON.encode(records[0].raw);
var jsonObj = Ext.JSON.decode(jsonStr);
alert(jsonStr);
}
});
Server response as follows:
{
"success": true,
"msg": "123"
}
I test callback param success, it is equals to true but records is blank [].
What's the reason? Please help me.
In your case you have to consider following things:
What really is your server response. If it is {"success":true, "msg":"123"}, then you really miss data.
You must set the name of the property which contains the data items in reader config. In ExtJS 4 this can be done with root, in EXTJS 5,6 with rootProperty.
If you load store data by code, set autoLoad to false.
ExtJS 4.2
reader: {
type: 'json',
root: 'data'
}
ExtJS 5 and ExtJS 6
reader: {
type: 'json',
rootProperty: 'data'
}
Notes:
I've reproduced your test case with EXTJS 4.2 and these are the reasons for such a behavior:
JSON response not contains data
root (rootProperty) config is not set.
JSON response contains data, but the name of the property which contains this data is not the same as in reader config.
Working example:
Server response:
{
"success": true,
"data": [
{"text": "Some words"},
{"text": "Some words"},
{"text":"Some words"}
]
}
HTML:
Ext.define('DeptModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type: 'string'}
]
});
Ext.onReady(function(){
var store = new Ext.create("Ext.data.TreeStore", {
model: "DeptModel",
proxy: {
type: 'ajax',
//url: 'jsonWebCommMenuOp_getMenus?PID=0',
// I've used simple PHP script to populate JSON response:
url: 'store-load.php',
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: false
});
store.load(
{
callback: function(records, options, success)
{
//var jsonStr = Ext.JSON.encode(records[0].raw);
//var jsonObj = Ext.JSON.decode(jsonStr);
//alert(jsonStr);
console.log(records);
}
});
});
There are some points below which are you need to recheck with your code:-
autoLoad instead of autoload.
With TreeStore you should mention root: {}
Have a look at this working fiddle.
Note: I am using data.json to request.
Hope this will help/guide you properly.
when I use insertChild() or Sync(), proxy sends GET to server with just _dc param, what I should do to save my tree via proxy?
EDIT:added writer, now ext doing POST but with no data
write listener also didn't call
Ext.define('App.model.FileTree',
{
extend : 'Ext.data.Model',
fields : [
{name : 'id', type: 'string'},
{name : 'name', mapping:'name', type: 'string'},
{name : 'text', type: 'string'},
]
});
Ext.define('App.store.FileTree', {
extend: 'Ext.data.TreeStore',
alias:'filestore',
model : 'App.model.FileTree',
proxy: {
actionMethods: {
create: 'POST',
destroy: 'DELETE',
read: 'GET',
update: 'POST'
},
type: 'ajax',
url : '/app/store/FileTree.php',
reader: {
type: 'json'
},
writer: {
type: 'json',
nameProperty: 'mapping'
}
},
listeners : {
write: function(store, operation, opts){
Ext.each(operation.records, function(record){
if (record.dirty) {
record.commit();
}
});
}
}
});
trying add child like:
var tree = Ext.ComponentQuery.query('filetree')[0];
var record = tree.getSelectionModel().getSelection()[0];
record.appendChild({text:'test',name:'test',id:2,leaf:true});
tree.store.sync();
Configure a writer inside the proxy. Without the writer proxy does not know what to do.
I have a tree in Ext 5.0 (but it works also in Ext 4.x) with tree model configured this way:
Ext.define('At.model.ContinentModel',{
extend:'Ext.data.TreeModel'
,alias:'model.continentmodel'
,idProperty:'id'
,fields:[
{name:'text', type:'string', persist:true}
,{name:'iconColor', type:'string'}
]
,proxy:{
type:'ajax'
,url:'resources/service.php/tree/read/1/'
,writer:{
type:'json'
,allowSingle:false
,encode:true
,rootProperty:'data'
}
}
});
The tree store is configured with autoSync:true. Changes in text field trigger server requests that look like this:
I am calling store , but while i print its data it says undefined
var store1 = Ext.create('Store1', {storeId: 'headerId'}).load({
params: {
gridFlag: 'gridHeader'
}
});
console.log(Ext.getStore(this.storeId).proxy.reader.rawData);
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
The property "proxy" does not exist - try getProxy or whatever
getStore().getProxy().getReader().rawData;
Sencha Documentation 4.2.2
I want to get data from mongo data base and add it to an extjs text area.
Everything is ready, my mongo data base returns a list of user email addresses that I want to add to the extjs text area.
I use this code:
var index = Ext.StoreMgr.lookup("writeup.store.Employee").findExact('name',name);
var rec = Ext.StoreMgr.lookup("writeup.store.Employee").getAt(index);
alert(rec.data.name);
But I get this error:
TypeError: Ext.StoreMgr.lookup(...) is undefined
And this is my store
Ext.define('writeup.store.Employee', {
extend: 'Ext.data.Store',
model: 'writeup.model.Employee',
autoLoad: true,
proxy: {
type: 'ajax',
actionMethods: {
read : 'POST'
},
api: {
read : 'user/view.action'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: false,
root: 'employee'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});
try this
Load this code into your controller
var store_name = Ext.create('Ext.data.Store', {
model: 'model name'
});
store_name.load();
store_name.each(function(record){
for(var i=0;i<record.data.yourlocalstorageid.length;i++){
var index = record.data.yourlocalstorageid[i].name;
}
}
Hello, I have a list with paging I want to send a param on load, this param is from another store.
Ext.define('WE3Chamados.store.Chamados', {
extend: 'Ext.data.Store',
config: {
model: 'WE3Chamados.model.Chamado',
autoLoad: false,
proxy: {
type: 'jsonp',
url: 'http://XXX/chamados.php',
callbackKey: 'callback',
reader: {
type: 'json',
rootProperty : 'chamados',
successProperty: 'success'
}
}
}
});
Like this
login_store = Ext.getStore('Login');
param_to_send_default = login_store.getAt(0).data.cod_usuario;
and send it as a default param.
You can use the extraParams config for the proxy object:
proxy: {
type: 'jsonp',
...
extraParams: {
param_to_send_default: Ext.getStore('Login').getAt(0).get('cod_usuario)
}
}