我有一个Panel,其中我有交替的组件。 我想获取组件的特定快照,然后我确实想要有时恢复它。 这样的事情:
takeSnapshot: function(){
var me = this,
panel = me.getRemarkPanel();
if(panel){
var content = panel.getRemarkContainer(),
currRows = content.query('> editorremarkline');
var snapshot = {
remarkLines: Ext.clone(currRows),
dirtyCmp: Ext.clone(panel.dirtyCmp),
removedRemarks: Ext.clone(panel.removedRemarks)
};
return snapshot;
}
},
restoreSnapshot: function(snapshot){
var me = this,
panel = me.getRemarkPanel();
if(panel && snapshot){
var content = panel.getRemarkContainer();
me.suspendLayouts();
content.removeAll();
content.add(snapshot.remarkLines);
panel.dirtyCmp = snapshot.dirtyCmp;
panel.removedRemarks = snapshot.removedRemarks;
me.resumeLayouts(true);
}
}
虽然在恢复我的快照时,我在渲染孩子时遇到错误。 我想我不能克隆我的组件清理它们并再次添加它们。
有没有办法解决这样的问题?请帮忙
答案 0 :(得分:0)
我已经找到了解决方案......关键是使用cloneConfig()方法克隆我的组件,如下所示:
takeSnapshot: function(){
var me = this,
panel = me.getRemarkPanel();
if(panel){
var content = panel.getRemarkContainer(),
currRows = content.query('> editorremarkline'),
remarkLines = [],
i = 0;
for(; i<currRows.length; i++){
remarkLines.push(currRows[i].cloneConfig());
}
var snapshot = {
remarkLines: remarkLines,
dirtyCmp: Ext.clone(panel.dirtyCmp),
removedRemarks: Ext.clone(panel.removedRemarks)
};
return snapshot;
}
},