PDA

View Full Version : Memory Proxy not working with comobobox



blossoms
4 Sep 2012, 10:20 PM
I am new to exjtjs and tried this code to load a combobox from memory proxy. But it doesnt seem to be working:

Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string', mapping: 'phoneNumber' }
]
});

var data = {
users: [
{
id: 1,
name: 'Ed Spencer',
phoneNumber: '555 1234'
},
{
id: 2,
name: 'Abe Elias',
phoneNumber: '666 1234'
}
]
};

var myJsonStore = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'User',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
});
myJsonStore.load();
Ext.getCmp('cmbPopulations').store = myJsonStore;

sword-it
4 Sep 2012, 10:57 PM
Hi Blossoms,

Your code work fine, see the sample working example for combobox-
http://jsfiddle.net/SBzFe/

tvanzoelen
4 Sep 2012, 11:15 PM
Probably you havent set the displayField and valueField properly

vietits
4 Sep 2012, 11:27 PM
Instead of assigning store to <combobox>.store, try to use <combobox>.bindStore(store). See http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.ComboBox-method-bindStore for more information.

blossoms
5 Sep 2012, 9:03 PM
Thanks sword-it. My code works if store is created before creating the formpanel. My use case is slighlty different. I have created a class that defines the form panel (alongwith combobox and other controls). I want to assign store and its data in OnReady function.

vietits -I tried using bindstore.. but it doesnt work

sword-it
5 Sep 2012, 11:18 PM
I guess you tried to find combobox before it render, See the following code -


Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{
name: 'id',
type: 'int'},
{
name: 'name',
type: 'string'},
{
name: 'phone',
type: 'string',
mapping: 'phoneNumber'}
]
});

var data = {
users: [
{
id: 1,
name: 'Ed Spencer',
phoneNumber: '555 1234'},
{
id: 2,
name: 'Abe Elias',
phoneNumber: '666 1234'}
]
};

var myJsonStore = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'User',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
});

var form = Ext.create('Ext.form.Panel', {
title: 'Simple Display',
autoHeight: true,
renderTo: Ext.getBody(),

items: [{
xtype: "combo",
itemId:'test',
fieldLabel:'Name',
hiddenName:'name',
//store:myJsonStore,
valueField:'id',
displayField:'name'}]
});

myJsonStore.load();
form.getComponent('test').bindStore(myJsonStore );


Here is working sample example - http://jsfiddle.net/YznyW/

blossoms
10 Sep 2012, 9:24 PM
Thanks sword-tr! It works now... It worked when I changed Ext.getCmp('') to form.getComponent.. What is the reason that Ext.getCmp() doesnt work in this case?

sword-it
10 Sep 2012, 10:26 PM
Thanks sword-tr! It works now... It worked when I changed Ext.getCmp('') to form.getComponent.. What is the reason that Ext.getCmp() doesnt work in this case?

getCmp(string id) : This method looks up an existing component by id.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-getCmp
(http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-getCmp)
getComponent(string/number comp) : Examines this container's items (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.container.AbstractContainer-property-items) property and gets a direct child component of this container by itemId or id.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.container.Container-method-getComponent