我想知道ExtJS中定义存储区与创建存储区的优缺点。如果实体很多,哪种方法更好?
答案 0 :(得分:0)
如果您定义商店,则如果需要,该商店(如果位于全球且不在视图模型内)将在应用启动过程中自动进行全局注册。
相反,如果您创建商店运行时,则需要先注册它,然后再将其用作全局商店(using regStore funcion)
我认为最终功能并没有真正的区别,在某些情况下,您需要创建一个商店运行时,在其他情况下,您不需要它,并且可以定义它。.
真正的区别是代码文件的顺序。.显然更好地是全局定义存储,以便在代码开发期间检查它们。
实际上,如果您需要一段时间后更新代码,则可能会失望地在代码行中搜索商店。相反,如果您有一个定义它的文件,则可以更快地搜索它。
很明显,在定义商店时,您还提供了一个类,可以在需要时反复使用。
因此,简而言之,如果您需要在代码中的多个位置,需要使用两次或多次,并且需要在代码文件夹中订购,请定义商店。 相反,在函数执行期间仅需要临时存储时,可以创建运行时存储。
快速提示:如果只需要在单个视图内存储,则在视图的视图模型中定义它,是使用视图模型体系结构的更好考虑。
答案 1 :(得分:0)
确实没有两种情况没有好与坏的情况。
问题是解决需要解决的问题的方法。
100%的案例建议您设置商店,也许您要问的问题是如何实例化商店。
在90%的情况下,我将使用要使用的默认模板实例化在应用程序中全局定义的商店。
在案例中,我需要使用10%的案例作为主要/明细功能,在这里我需要打开同一功能的多个实例。如果我没有为每个功能实例实例化存储,则存储中的每个更改或负载都将复制到其他打开的功能中,这对用户来说是一个严重的错误。
在全球范围内设置商店。
这是在本地实例化的示例。
/**
* @class Litus.view.segundaviaBoleto.Grid
* Listagem de 2º via de boletos
*/
Ext.define('Litus.view.segundaviaBoleto.Grid',{
extend: 'Ext.grid.Panel',
xtype: '2viaBoleto-Grid',
require: [
'Litus.store.segundaviaBoleto.Store'
],
allowPaging: false,
multiSelect: false,
viewConfig: {
stripeRows: true,
enableTextSelection: true
},
/**
* @method initComponent
* Tratamento da inicialização do componente.
* @protected
*/
initComponent: function () {
var me = this;
//Locally instantiated the store at the start of the grid component, because this grid is opened several times.
me.store = Ext.create('Litus.store.segundaviaBoleto.Store');
Ext.applyIf(me, {
columns: [{
text: 'Documento',
width: 190,
sortable: false,
dataIndex: 'NumeroDocumento',
align: 'center',
style: 'text-align: center'
}, {
xtype: 'datecolumn',
text: 'Vencimento',
width: 130,
sortable: false,
dataIndex: 'DataVencimento',
format: 'd/m/Y',
align: 'center',
style: 'text-align: center'
}, {
xtype: 'numbercolumn',
text: '(R$) Valor',
width: 130,
align: 'right',
sortable: false,
dataIndex: 'ValorAtual',
style: 'text-align: center',
format: '#,##0.00'
}, {
text: 'Empresa',
flex: 1,
sortable: false,
dataIndex: 'Descricao',
align: 'left',
style: 'text-align: center'
}]
});
me.callParent(arguments);
}
});