所以,我在我的代码中有一个数据存储,我正在加载一个函数。在该存储区中,我希望使用each method以某种格式将每条记录附加到面板主体。
我想弄明白的是如何使用这个"each“方法。以前有没有人用过它?一般来说,我对函数和编程比较陌生,所以我想弄清楚"fn“和"scope”相对于我自己的代码是什么。
如果有人以前在ExtJS框架中使用过这种方法,那么任何帮助都将是非常棒的。
发布于 2010-08-26 15:23:32
在您的案例中使用Dataview。将商店和XTemplate添加到您的数据视图中,并将此数据视图作为项目添加到面板中。它将是这样的:
this.store = new Ext.data.JsonStore({
url : 'myproxy.php',
baseParams : {
action : 'get_basket_files'
},
root : 'rows',
id : 'filename',
fields : ['filename', 'filepath', 'filesize', 'fileclass']
});
this.filesTemplate = new Ext.XTemplate(
'<div class="files_container"><tpl for=".">',
'<div id="{filename}" class="basket-fileblock"><div class="{fileclass}"></div>',
'<div class="filetext">{filename}</div></div> ','</tpl></div>');
this.filesTemplate.compile();
this.filesDataView = new Ext.DataView({
itemSelector : 'div.basket-fileblock', //Required
style : 'overflow:auto',
multiSelect : true,
store : this.store,
tpl : this.filesTemplate
});
var panel = new Ext.Panel({
layout : 'fit',
items : [this.filesDataView]
});这里的XTemplate是每个项目的超文本标记语言模板。请看一下ExtJS文档,其中提供了许多XTemplate示例。
举个例子,ExtJS每个函数都可以这样使用:
假设一个项目数组为myItems。所以,
Ext.each(myItems, function(eachItem){
//Do whatever you want to do with eachItem
}, this);发布于 2010-08-26 11:46:46
听起来你想要一个Ext.DataView。
DataView使用模板或XTemplate在存储中创建数据呈现。
因此,您实例化一个已配置的数据视图,包括对您的存储的引用和要使用的模板,并将该dataview添加到您的面板中。
https://stackoverflow.com/questions/3571892
复制相似问题