vendredi 2 janvier 2015

Filtering in a association model under sencha touch 2


I have a form with different parameters and nested json, here the code:



{
"orderoptions": [
{
"id": "10",
"rdd": "20150108",
"headerfieldconfigs": [
{
"propertyname": "name",
"propertyvalue": "rdd",
"required": "true",
"hidden": "false",
"propertyoptions": []
},
{
"propertyname": "name",
"propertyvalue": "poNr",
"required": "false",
"hidden": "false",
"propertyoptions": []
},
{
"propertyname": "name",
"propertyvalue": "shipManually",
"required": "false",
"hidden": "false",
"propertyoptions": []
},
{
"propertyname": "name",
"propertyvalue": "name",
"required": "true",
"hidden": "false",
"propertyoptions": []
},
{
"propertyname": "name",
"propertyvalue": "region",
"required": "true",
"hidden": "false",
"propertyoptions": [
{
"text": "Agriento",
"value": "AG",
"country": "IT"
},
{
"text": "Alessandria",
"value": "AL",
"country": "IT"
},
{
"text": "Ancona",
"value": "AN",
"country": "IT"
},
{
"text": "Aosta",
"value": "AO",
"country": "IT"
},
{
"text": "Arezzo",
"value": "AR",
"country": "IT"
},
{
"text": "Ascoli Piceno",
"value": "AP",
"country": "IT"
},
{
"text": "Asti",
"value": "AT",
"country": "IT"
},
{
"text": "San Marino",
"value": "SM",
"country": "SM"
},
{
"text": "Bari",
"value": "BA",
"country": "IT"
},
{
"text": "BarlettaAndriaTrani",
"value": "BT",
"country": "IT"
},
{
"text": "Belluno",
"value": "BL",
"country": "IT"
}],
{
"propertyname": "name",
"propertyvalue": "country",
"required": "true",
"hidden": "false",
"propertyoptions": [
{
"text": "Italy",
"value": "IT",
"country": "IT"
},
{
"text": "San Marino",
"value": "SM",
"country": "SM"
}
]
},
]}


Concretely I have two selectfields called region and country and depending of the country you should select determinated regions in this example we have two countries, Italy and San Marino. Here the store code with the associated model.


How to filter properly and I select Italy to see the Italy regions and so on... ??



Ext.define('OrderOption', {
extend: 'Ext.data.Model',
requires: [
'FieldConfig'
],

config: {
useCache: false,
idProperty: 'id',
fields: [
'id',
'salesarea',
'ordertype',
'ordertypetext',
'rdd'
],
associations: [

{
type: 'hasMany',
associatedModel: 'FieldConfig',
ownerModel: 'OrderOption',
name: 'headerfieldconfigs',
associationKey: 'headerfieldconfigs'
}

]
}
});


In the controller I have started the implementation but It is not working properly..



onShipManuallyCountryChange: function(field, newValue, oldValue, eOpts){
var store = Ext.getStore('OrderOptions');
switch (newValue) {
case 'SM' :
this.getShipManuallyRegion().setValue(newValue);
break;
case 'IT' :
this.getShipManuallyRegion().setValue('Agriento');
break;
}
},


Any example?? thanks!!





Aucun commentaire:

Enregistrer un commentaire