开发者

Belongs to association in Sencha

开发者 https://www.devze.com 2023-04-05 00:12 出处:网络
How can i f开发者_运维技巧etch a record using belongs to association ? var Category = Ext.regModel(\'Category\', {

How can i f开发者_运维技巧etch a record using belongs to association ?

var Category = Ext.regModel('Category', {
fields: [
    {name: 'id',   type: 'int'},
    {name: 'name', type: 'string'}
]
});

var Product = Ext.regModel('Product', {
    fields: [
        {name: 'id',          type: 'int'},
        {name: 'category_id', type: 'int'},
        {name: 'name',        type: 'string'}
    ],

associations: [
    {type: 'belongsTo', model: 'Category'}
]

});


Amol,

I speak only of ExtJS 4, so if you can relate this to ExtJS 3 then great, but you would retrieve multiple records via a store:

As a starting point though you could do

var records = Ext.StoreManager.lookupStore("productStore").load({
      belongTo: 'books',
      callback: function(records) {
           Ext.each(records,function(record) {
              console.log(JSON.stringify(record.raw))
           });
      }
 });

Depending on the proxy setup on the productStore, this will append belongTo to the querystring so if reader proxy has url: /products and the extra params belongTo is sent this will hit the server with /products?belongTo=books

0

精彩评论

暂无评论...
验证码 换一张
取 消