-
18 Jul 2012 1:35 PM #1
Unanswered: data association HasMany with no fields
Unanswered: data association HasMany with no fields
Hello ,
i have a XML like this :
Code:<items> <item> <type>Concert</type> <artistes> <artiste>Bruce Springsteen</artiste> <artiste>Madonna</artiste> <artiste>Pink Floyd</artiste> </artistes> <link>http://wwww.aaaaaaaaa.com</link> </item> </items>
but I can't read the "artiste" field with a model without fields :
PHP Code:Ext.define('MyApp.model.artiste', {
extend: 'Ext.data.Model',
config: {
}
});
and I have this error :PHP Code:Ext.define('MyApp.model.news', {
extend: 'Ext.data.Model',
uses: ['MyApp.model.artiste'],
config: {
idProperty: 'news',
fields: [
{name: 'type',type: 'string'},
{name: 'link'}
],
hasMany: {
model: 'MyApp.model.artiste',
autoLoad: true,
name: 'artistes'}
}
});
How can I do that ? i tried with a memory proxy but without any success ...Code:[WARN][Ext.data.Operation#process] Unable to match the record that came back from the server.
Will you help me ?
-
18 Jul 2012 1:44 PM #2
I suppose you will need to add the "associationKey" property in the "hasMany" config.
http://docs.sencha.com/touch/2-0/#!/...associationKey
Code:hasMany: { model: 'MyApp.model.artiste', autoLoad: true, name: 'artistes', /* This is going to be a store name. ex) record.artistesStore */ associationKey: 'artistes', /* The name of the property in the data to read the association from */ }
-
18 Jul 2012 1:49 PM #3
Thank you to answer me , but it still no work
.
-
18 Jul 2012 2:08 PM #4
Why do you have this?
idProperty: 'news',Show us store definitions as well.
-
18 Jul 2012 2:14 PM #5
it was a try ... I removed it .PHP Code:idProperty: 'news',

here my store :
PHP Code:Ext.define('MyApp.store.NewsXmlStore', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.news'
],
config: {
autoLoad: true,
autoSync: true,
model: 'MyApp.model.news',
storeId: 'NewsXmlStore',
proxy: {
type: 'ajax',
url: 'http://www.welovemusic.fr/testflux',
reader: {
type: 'xml',
idProperty: 'NewsXmlReader',
rootProperty: 'items',
record: 'item'
}
}
}
});
-
18 Jul 2012 2:17 PM #6
Don't play with idProperty if you don't really know what it is doing

reader: {Why did you set idProperty: 'NewsXmlReader' ?
type: 'xml',
idProperty: 'NewsXmlReader',
rootProperty: 'items',
record: 'item'
}
-
18 Jul 2012 2:35 PM #7
ok , I understood the lesson : i removed all "idProperty" !

but it still not work
the full code :
PHP Code:Ext.define('MyApp.store.NewsXmlStore', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.news'
],
config: {
autoLoad: true,
autoSync: true,
model: 'MyApp.model.news',
storeId: 'NewsXmlStore',
proxy: {
type: 'ajax',
url: 'http://www.welovemusic.fr/testflux',
reader: {
type: 'xml',
rootProperty: 'items',
record: 'item'
}
}
}
});
PHP Code:Ext.define('MyApp.model.news', {
extend: 'Ext.data.Model',
uses: [
'MyApp.model.artiste'
], config: {
fields: [
{
name: 'type',
type: 'string'
},
//here : a lot of fields ...
{
name: 'link'
},
],
hasMany: {
associationKey: 'artistes',
model: 'MyApp.model.artiste',
autoLoad: true,
name: 'artistes'
}
}
});
PHP Code:Ext.define('MyApp.model.artiste', {
extend: 'Ext.data.Model',
config: {
}
});
and finally :
PHP Code:Ext.define('MyApp.view.MyList', {
extend: 'Ext.dataview.List',
config: {
store: 'NewsXmlStore',
itemTpl: [
'<div>{type}</div>', // it's ok for that
'<br />',
'<tpl for="artistes">', // nothing appears ...
' <p>{artiste}</p>',
'</tpl>'
]
}
});
-
18 Jul 2012 3:14 PM #8
Try to read here about models and association:
http://www.sencha.com/forum/showthread.php?220417-Using-Model-associations-with-two-proxied-Stores
Your association is not fully defined. Artistes record is artiste but there is no mention of that in your models
-
19 Jul 2012 4:39 AM #9
thank you for the advice and the link : the example is a little bit complex for me , but I'm trying to figure how to apply it on my problem .


Reply With Quote