2012-07-30 47 views
0

我有以下的店鋪:清除數據存儲和重新填充它

Ext.define('Sencha.store.AdultMenuStore', { 
extend: 'Ext.data.Store', 

config: { 
    onItemDisclosure: true, 
    model:'Sencha.model.MenuPoint', 
    data: [ 
     { 
      id: 'addChild', 
      name: 'Add child', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-plussign.png', 
      xtype: 'addchildform' 
     },{ 
      id: 'share', 
      name: 'Share', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-shareicon.png', 
      xtype: 'childmenu' 
     },{ 
      id: 'myProfile', 
      name: 'My Profile', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-profile.png', 
      xtype: 'childmenu' 
     },{ 
      id: 'help', 
      name: 'Help', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-question.png', 
      xtype: 'childmenu' 
     }] 
} 
}); 

它採用以下模式:

Ext.define('Sencha.model.MenuPoint', { 
extend: 'Ext.data.Model', 

config: { 
    fields: [ 
     {name: 'id', type: 'string'}, 
     {name: 'name', type: 'string'}, 
     {name: 'icon_url', type: 'string'}, 
     {name: 'xtype', type: 'string'} 
    ] 
} 
}); 

在代碼中有些地方我動態添加菜單點是這樣的:

有時我需要清除商店,ergo刪除我動態添加的菜單點,只使用m在商店中硬編碼的enu點。我看到了在商店中刪除和添加的方法,但我不知道如何重置商店並使用我在那裏定義的靜態數據重新填充商店。

回答

1

做,因爲我已經回答了你的問題上一張,你不尊重:)

var data = [ 
     { 
      id: 'addChild', 
      name: 'Add child', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-plussign.png', 
      xtype: 'addchildform' 
     },{ 
      id: 'share', 
      name: 'Share', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-shareicon.png', 
      xtype: 'childmenu' 
     },{ 
      id: 'myProfile', 
      name: 'My Profile', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-profile.png', 
      xtype: 'childmenu' 
     },{ 
      id: 'help', 
      name: 'Help', 
      icon_url: 'http://kidsparent.no/images/adultMenu/bkids-home-question.png', 
      xtype: 'childmenu' 
     }] 

store.load(function (store) { 
    store.add(data)// data is an array with you local data 
}) 

store.load()函數清理分組數據

乾杯,奧列格

+0

再次謝謝奧列格,你一遍又一遍地保存我的一天)) – 2012-07-30 10:11:38

相關問題