我正在关注这个过滤器的小提琴TreePanel
。我的目标是隐藏几项TreeStore
取决于登录帐户的username
.
我在login
我的应用程序的方法上使用了小提琴的想法,但现在它显示了任何项目!怎样才能克服这种情况?
login: function (username, password) {
var me = this;
var params = {
// Headers
'username': username,
'password': password,
...
};
var loginReq = {...} // Saves token with a promise function
if (username === 'test@useradress.com') {
var treeStore = Ext.getStore('navMenuTree');
//debugger; //Error raises on here but doesn't give any error on console.
treeStore.filterBy(function (item) {
if (item.get('root') === true) return true;
else if (item.get('visibleModule') === 1) return true;
else return false;
});
}
return loginReq;
},
我已经定义了小提琴中提到的 TreeStore ;
Ext.define('MyApp.store.NavMenuTree', {
extend: 'Ext.data.TreeStore',
alias: 'store.navmenutree',
storeId: 'navMenuTree',
fields: [{
name: 'text'
}],
root: {
expanded: true,
defaultRootProperty: 'data',
visibleModule: 1, //Here it is.
data: [
{
text: 'First Menu Item', //Which should be "visible"
visibleModule: 1,
iconCls: 'x-fa fa-thumbs-up',
expanded: false,
selectable: false,
data: [
{
text: translations.dashboard,
iconCls: 'x-fa fa-area-chart',
viewType: 'dash',
leaf: true,
visibleModule: 1 // As well childrens should be visible
},
{
text: translations.bonus,
iconCls: 'x-fa fa-pencil-square-o',
viewType: 'bonuslist',
leaf: true,
visibleModule: 1 //Here also!
}
]
},
{
text: 'Menu Item 2', //Which should be "hide"
visibleModule: 2,
iconCls: 'x-fa fa-usd',
expanded: false,
selectable: false,
data: [
{...}
]
},