[英]Can not to implement filterBy method for TreeStore in Ext JS?
我正在跟蹤過濾TreePanel
小提琴 。 我的目的是根據登錄帳戶的username
隱藏一些TreeStore
項目。
我已經在我的應用程序的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: [
{...}
]
},
rootProperty定義應位於商店的代理的讀取器中
例如:
Ext.define('MyApp.store.NavMenuTree', {
extend: 'Ext.data.TreeStore',
alias: 'store.navmenutree',
storeId: 'navMenuTree',
proxy : {
type: 'ajax',
reader : {
type: 'json',
rootProperty : 'data'
}
}
我已經成功地通過提到的小提琴和我自己的結構過濾了項目。
引發該問題的唯一的事情就是storeId
財產TreeStore
。 由於某種未知原因而被評論! 如果未評論,則以某種方式刪除了整個導航菜單項。
因此,我對此進行了評論,並在Ext.getStore()
方法上使用了TreeStore
自己的名稱。 通過這種方式解決了問題,scenerio完美運行。
if (username === 'test@useradress.com') {
//Updated only this part. In my case it's Ext.getStore('NavMenuTree')
var treeStore = Ext.getStore('NameOfTreeStore');
treeStore.filterBy(function (item) {
if (item.get('root') === true) return true;
else if (item.get('visibleModule') === 1) return true;
else return false;
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.