2015-11-23 2 views
1

Я пытаюсь реализовать простую связь родительских детей в одной и той же сущности с Ext js 6, где я получу всю информацию в JSON. Он отлично работает для родителя, но я не могу отображать детей в сетке. Я предполагаю, что это что-то очень просто и ошибка должна быть в модели:hasMany auto relation in ext JS 6

Ext.define('hashmanytest.model.Person', { 
extend: 'Ext.data.Model', 
alias: 'model.Person', 


hasMany: { 
    model: 'hashmanytest.model.Person', 
    name: 'childs', 
    associationKey: 'childs' 
}, 



fields: [ 
    { name:'name' , type:'string' }, 
    { name:'email' , type:'string' }, 
    { name:'phone' , type:'string' }, 
    { name:'id' , type:'string' }, 
    { name: 'parent', reference: 'hashmanytest.model.Person'} 
] 
}); 

Или в магазине:

Ext.define('hashmanytest.store.Personnel', { 
extend: 'Ext.data.Store', 

alias: 'store.personnel', 

model: 'hashmanytest.model.Person', 

data: { items: [ 
    { name: 'Jean Luc', email: "[email protected]", phone: "555-111-1111", id:1, parent: {}, childs: [ 
     { name: 'Worf',  email: "[email protected]", phone: "555-222-2222", id:2}, 
     { name: 'Deanna', email: "[email protected]", phone: "555-333-3333", id:3}, 
     { name: 'Data',  email: "[email protected]",  phone: "555-444-4444", id:4} 
    ]}, 
    { name: 'Worf',  email: "[email protected]", phone: "555-222-2222", id:2, parent:{ name: 'Jean Luc', email: "[email protected]", phone: "555-111-1111", id:1}, childs: []}, 
    { name: 'Deanna', email: "[email protected]", phone: "555-333-3333", id:3, parent:{ name: 'Jean Luc', email: "[email protected]", phone: "555-111-1111", id:1}, childs: []}, 
    { name: 'Data',  email: "[email protected]",  phone: "555-444-4444", id:4, parent:{ name: 'Jean Luc', email: "[email protected]", phone: "555-111-1111", id:1}, childs: []} 
]}, 

proxy: { 
    type: 'memory', 
    reader: { 
     type: 'json', 
     rootProperty: 'items' 
    } 
} 
}); 

Во всяком случае я создал скрипку с реализацией: https://fiddle.sencha.com/#fiddle/11gr

Любая помощь была бы действительно оценена

ответ

2

Модель в порядке, record.childs() возвращает store. Используйте getCount() вместо length:

{ 
    text: 'Children', 
    sortable: true, 
    flex: 2, 
    renderer: function (value, metaData, record) { 
     return record.childs().getCount();  
    } 
} 

https://fiddle.sencha.com/#fiddle/11gs

Смежные вопросы