ExtJS4:将参数/属性从 Treestore 传递到控制器
我正在使用一个没有代理的简单 TreeStore 来构建我的菜单。这是一个简单的示例:
Store:
Ext.define('LT.store.MnuApplication', {
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
children: [{
text: "Lists",
expanded: true,
children: [{
text: "Countries",
leaf: true,
}]
}]
}
});
在控制器中,我为“click”事件添加了一个监听器:
Controller:
init: function() {
this.control({
/**
* Catch the treepanels in the menu accordion
*/
'menu-main treepanel': {
itemclick: function (view, record, item, index, event){
var clickedMnuNode = record;
var tabPanel = this.getTabPanel();
// Open tab only if the menu node is a leaf node
if (clickedMnuNode.isLeaf()) {
tabPanel.add({
xtype: clickedMnuNode.raw.loadTabComponent
}).show();
}
}
}
});
this.callParent();
}
现在解决我的问题:我想要在 TreeStore 中定义哪些操作应该由控制器完成 - 特别是应该加载哪个组件。
例如,我希望 TreeStore 看起来像这样:
Ext.define('LT.store.MnuApplication', {
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
children: [{
text: "Lists",
expanded: true,
children: [{
text: "Countries",
leaf: true,
loadComponent: 'country-list',
loadTarget: 'tabPanel'
}]
}]
}
});
如您所见,我向 Tree Leaf 添加了两个新参数。现在我可以通过记录的“RAW”方法访问这些数据集。但这并不是一个很好的解决方案 - 不是吗?
那么有人对我有想法吗,如何将附加参数(如“loadComponent”或“loadTaget”)从我的 TreeStore 传递到控制器?
提前致谢&干杯, 迈克尔
I´m using a simple TreeStore without proxies for building my Menu. Here is a simple Example:
Store:
Ext.define('LT.store.MnuApplication', {
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
children: [{
text: "Lists",
expanded: true,
children: [{
text: "Countries",
leaf: true,
}]
}]
}
});
In the controller I´ve added a listener to the "click" event:
Controller:
init: function() {
this.control({
/**
* Catch the treepanels in the menu accordion
*/
'menu-main treepanel': {
itemclick: function (view, record, item, index, event){
var clickedMnuNode = record;
var tabPanel = this.getTabPanel();
// Open tab only if the menu node is a leaf node
if (clickedMnuNode.isLeaf()) {
tabPanel.add({
xtype: clickedMnuNode.raw.loadTabComponent
}).show();
}
}
}
});
this.callParent();
}
And now to my problem with this solution: I want to define in the TreeStore, which actions should be done by the controller - especially which component should be loaded.
For example I would like that the TreeStore looks like this:
Ext.define('LT.store.MnuApplication', {
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
children: [{
text: "Lists",
expanded: true,
children: [{
text: "Countries",
leaf: true,
loadComponent: 'country-list',
loadTarget: 'tabPanel'
}]
}]
}
});
As you can see I´ve added two new parameters to the Tree Leaf. Now I cann access those datasets via the "RAW" method of the record. But that´s not really a nice solution - isn´t it?
So has anyone an idea for me, how to pass additional parameters (like "loadComponent" or "loadTaget") from my TreeStore to the controller?
Thanks in advance & cheers,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
过去,我使用自定义参数创建了类似的树,并为 TreeStore 使用了自定义模型。因为默认情况下你的节点只有 NodeInterface 的属性。像这样的事情:
In the past I created similar tree with my custom parameters and I used a custom model for my TreeStore. Because by default your node, just has properties of NodeInterface. Something like this: