PDA

View Full Version : New records are saved in store, but show only after refresh of page.



HristinaP
10 May 2017, 3:45 AM
0down votefavorite (http://stackoverflow.com/questions/43891243/new-records-are-saved-in-store-but-show-only-after-refresh-of-page#)


this a Sencha code which I am supposed to fix, however I don't understand why after creating new records to a store, they don't show immediately, but, only after refresh(?). Below are the relevant pieces of code.
Thank you.




Hi, I am new to Sencha and this is code which I am supposed to fix, but, I don't understand why when adding new records to a store I can see them being saved as objects, but, in the web application are shown only after refresh and not at-the-time of making.

Below are the relevant pieces of code, thank you.

Controller


click:function(button){var window = button.up('window');
var form = window.down('form#formTemplateWindow');

if(window.action =="add"){
if(form.isValid()){
var store =this.getDataViewList().getStore();
var zones =newArray();
Ext.each(form.zones,function(value, key){
zones.push(value.data.id);
});
var record = form.getValues();
record.zones = zones;
store.add(record);
store.sync();
button.up('window').close();
}}

Model

Ext.define("dsaweb.model.Template",{extend:"Ext.data.Model",
fields:[
'id',
'name',
'layout_id',
{
name:'reg_date',
type:'date',
dateReadFormat:'Y-m-d H:i:s',
dateWriteFormat:'Y-m-d H:i:s'
},{
name:'background',
type:'auto'
},{
name:'color1',
type:'string'
},{
name:'color2',
type:'string'
},{
name:'url',
type:'string'
},{
name:'degree',
type:'string'
},{
name:'playlists',
type:'auto'
},{
name:'zones',
type:'auto'
}
]});

Store

Ext.define("dsaweb.store.Template",{extend:"Ext.data.Store",
autoSync:true,
autoLoad:false,
model:"dsaweb.model.Template",
proxy:{
type:"rest",
url:dsaweb.util.Config.TEMPLATE_URI,
reader:{
type:"json",
root:"result"
}
},

sorters:[
{
property:'Name',
direction:'ASC'
}
]});