PDA

View Full Version : error: store not defined



shikhasachdeva89
30 Apr 2013, 3:21 AM
if i want to make a different store in this code then it says store not defined
here is the code
Js file
Ext.define('MyApp.view.new', {
extend: 'Ext.form.ComboBox',



queryMode: 'remote',
displayField: 'name',
valueField: 'abbr',
forceSelection: true,
id: 'searchId',
labelWidth: 150,
fieldLabel: 'Search',
size: 50,
maxLength: 50,
allowBlank : false,
name: 'AppSearch',

minChars: 1,
hideTrigger:true,
typeAhead: true,
store: 'searchStore',
listeners: {
buffer: 50,
change: function() {
var store = this.store;

//store.suspendEvents();
store.clearFilter();
//store.resumeEvents();
store.filter({
property: 'name',
anyMatch: true,
value : this.getValue()
});
}
}


});

Store




Ext.define('MyApp.store.searchStore', {
extend: 'Ext.data.Store',


requires: [
'MyApp.model.searchModel'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
model: 'MyApp.model.searchModel',
storeId: 'HeaderStoreId',
proxy: {
type: 'ajax',
url: 'http://localhost:8080/combo/view/data/data.json',
reader: {
type: 'json',
root: 'SearchData'
},
writer: {
type: 'json'
}
}
}, cfg)]);
}
});
Model


Ext.define('MyApp.model.searchModel', {
extend: 'Ext.data.Model',


fields: [
{
name: 'abbr'
},
{
name: 'name'
},
{
name: 'slogan'
}
]
});
Json file
{
"success": true,
"SearchData": [
{"abbr":'VA',
"name": 'Virginia',
"slogan":'Mother of States'
},
{"abbr":'WA',
"name": 'Washington',
"slogan":'Green Tree State'
},
{"abbr":'WV',
"name": 'West Virginia',
"slogan":'Mountain State'
},
{"abbr":'WI',
"name": 'Wisconsin',
"slogan":'America\'s Dairyland'
},
{"abbr":'WY',
"name": 'Wyoming',
"slogan":'Like No Place on Earth'
}

]
}


in this code error is store is undefined.
please tell me where is the mistake.

slemmon
1 May 2013, 4:20 PM
If you're setting your application up using Ext.application and have your controllers setting up a store using the stores config on a controller then the controller will auto-create an instance of that store (MyApp.store.searchStore in your case) and that store instance will have a storeId of searchStore. Then you can use that to reference the store like in your config - store: 'searchStore'.

If you're not using an MVC build with Ext.application then you'll need to first create an instance of the MyApp.store.searchStore. You could do that prior to creating the combo and either in the creation of it set the storeId to 'searchStore' or you can put the storeId in the store definition and then you can call up that store instance using the storeId like in your example.