PDA

View Full Version : ExtJS 4.0 and WCF webservices.



mushi1
2 Apr 2012, 11:26 PM
Hi all,
I am new to ExtJS and using extjs 4.0, can any one please post a single call code for calling a WCF web service in extjs by passing one or more params.

mitchellsimoens
3 Apr 2012, 11:24 AM
Like an Ext.Ajax.request or a store call?

mushi1
4 Apr 2012, 4:04 AM
mitchellsimoens,
Thanks for replying, it will be very helpful if post both of methedologies and it will be very kind of you if you guide me how to define model for hierarchical data (JSON) resturned by web service, because eventually i want to populate Xtemplate tpl with it. JSON is as below.


{
"Units": [
{
"UnitName": "6010",
"Color": "red",
"JobGroups": [
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "LVN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN1",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN2",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN3",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN4",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN5",
"HoursOver": "+3",
"HoursUnder": "-3"
}
]
},
{
"UnitName": "6012",
"Color": "red",
"JobGroups": [
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "LVN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN1",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN2",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN3",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN4",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN5",
"HoursOver": "+3",
"HoursUnder": "-3"
}
]
},
{
"UnitName": "6011",
"Color": "red",
"JobGroups": [
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "LVN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN1",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN2",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN3",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN4",
"HoursOver": "+3",
"HoursUnder": "-3"
},
{
"Name": "RN5",
"HoursOver": "+3",
"HoursUnder": "-3"
}
]
}
]
}

mitchellsimoens
4 Apr 2012, 4:45 AM
All you have to do is set the root config in the reader config of the store to 'Units' and in your model you can have a field 'JobGroups' and leave the type as the default 'auto'. That will not try to transform the JobGroups and leave it as an array.

mushi1
4 Apr 2012, 10:21 AM
mitchellsimoens,
Thanks for this quick reply, the hierarchical thing is working fine, but still i have no luck with WCF webservice using store, can you please post a smaple store code to get json from in domain WCF webservice call.

mitchellsimoens
4 Apr 2012, 10:56 AM
Ext.define('MyApp.model.Unit', {
extend : 'Ext.data.Model',

fields : [
'UnitName',
'Color',
'JobGroups'
]
});

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

requires : 'MyApp.model.Unit',

model : 'MyApp.model.Unit',
proxy : {
type : 'ajax',
url : '.....',
reader : {
type : 'json',
root : 'Units'
}
}
});

That should be able to read the JSON you provided and keep JobGroups as an array.