Association Sample in extjs 4.2: -
can 1 please point me working example of association (with hasmany , belongsto) in extjs. please don't point me sencha docs or examples related sencha because had tried none of them works...
running sample (turn on browser console):
ext.define('my.model.author', { extend:'ext.data.model', fields:[ 'name' ] }); ext.define('my.model.comment', { extend:'ext.data.model', fields:[ 'emailaddress', 'body' ] }); ext.define('my.model.blogpost', { extend:'ext.data.model', fields:[ 'title', 'body' ], belongsto:[ { name:'author', instancename:'author', model:'my.model.author', gettername:'getauthor', settername:'setauthor', associationkey:'author' } ], hasmany:[ { name:'comments', model:'my.model.comment', associationkey:'comments' } ], proxy:{ type:'ajax', url:'https://dl.dropboxusercontent.com/u/1015920/ext/blog-posts.json', reader:{ type:'json', root:'data' } } }); my.model.blogpost.load(1, { success:function(record, operation){ console.log(record.get('title')); // "some title" console.log(record.getauthor().get('name')); // "neil" console.log(record.comments().getcount()); // 2 } }); read more here:
http://extjs-tutorials.blogspot.ca/2012/05/extjs-belongsto-association-rules.html
http://extjs-tutorials.blogspot.ca/2012/05/extjs-hasmany-relationships-rules.html
the sample data used:
{ "data": [ { "id": 1, "title": "some title", "body": "some body", "author": {"id":1, "name": "neil"}, "comments": [ { "id":55, "emailaddress": "user@example.com", "body": "test comment" }, { "id":66, "emailaddress": "user2@example.com", "body": "another comment" } ] } ] }
Comments
Post a Comment