I have a Transaction and TransactionId which is associated with each Transaction. The TransactionId is a composite key, so, I wrote a new property and have overridden the convert function. When I use alert to get the properties, it is returning undefined.
However, If I put all the properties in the same model, I am able to retrieve the properties when I alert. Could you suggest if I am doing anything wrong?
The json data is as follows:
If I put the following code, I am not able to retrieve the properties inside the TransactionId model.
Code:
Ext.define('Transaction', {
extend: 'Ext.data.Model',
idProperty: 'assetTxId',
fields: [{
name: 'aset01fkCurrCd'
}, {
name: 'firmStatus'
}, {
name: 'amt',
type: 'float'
}, {
name: 'valueDate',
type: 'date',
dateFormat: 'Y-m-d'
}, {
name: 'assetTransType'
}, {
name: 'assetTxId',
type:'string',
convert: function(value,record) {
alert(record.get('creationDate'));
return record.get('creationDate')
+ record.get('nbr')
+ record.get('dcoId');
}
}],
hasOne: [{
name: 'TransactionId',
model: 'TransactionId',
associationKey: 'id' // <- this is the same as what is in the JSON response
}],
});
Ext.define('TransactionId', {
extend: 'Ext.data.Model',
fields: [{
name: 'creationDate',
type: 'date',
dateFormat: 'Y-m-d'
}, {
name: 'nbr',
type: 'float'
}, {
name: 'dcoId',
}]
});
However, If I put all the properties in the same model, I am able to retrieve the properties when I alert. Could you suggest if I am doing anything wrong?
Here is my working code.
Code:
Ext.define('Transaction', {
extend: 'Ext.data.Model',
idProperty: 'TransactionId',
fields: [{
name: 'aset01fkCurrCd'
}, {
name: 'firmStatus'
}, {
name: 'amt',
type: 'float'
}, {
name: 'valueDate',
type: 'date',
dateFormat: 'Y-m-d'
}, {
name: 'assetTransType'
}, {
name: 'creationDate',
mapping: 'id.creationDate',
type: 'date',
dateFormat: 'Y-m-d'
}, {
name: 'nbr',
mapping: 'id.nbr',
type: 'numberfield'
}, {
name: 'dcoId',
mapping: 'id.dcoId',
}, {
name: 'TransactionId',
type:'string',
convert: function(value,record) {
return record.get('creationDate')
+ record.get('nbr')
+ record.get('dcoId');
}
}]
});
The json data is as follows:
Code:
[
{
"id": {
"creationDate": 1393567200000,
"nbr": 619,
"dcoId": "CDO"
},
"amt": 65000000,
"aset01fkCurrCd": "USD",
"assetTransType": "DW",
"firmStatus": "VRFYD",
"valueDate": 1393567200000
},
{
"id": {
"creationDate": 1393567200000,
"nbr": 513,
"dcoId": "CDO"
},
"amt": -4607329.03,
"aset01fkCurrCd": "USD",
"assetTransType": "WD",
"firmStatus": "VRFYD",
"valueDate": 1393567200000
},
{
"id": {
"creationDate": 1393567200000,
"nbr": 598,
"dcoId": "CDO"
},
"amt": 69305.02,
"aset01fkCurrCd": "USD",
"assetTransType": "DW",
"firmStatus": "VRFYD",
"valueDate": 1393567200000
}
]
Aucun commentaire:
Enregistrer un commentaire