admin管理员组文章数量:1312774
Im trying to loop a array with extjs xtemplate and create a table
Ext.define('dataview_model', {
extend : 'Ext.data.Model',
fields : [
{name: 'count', type: 'string'},
{name: 'maxcolumns', type: 'string'},
{name: 'maxrows', type: 'string'},
{name: 'numbers', type: 'array'}
]
});
Ext.create('Ext.data.Store', {
storeId : 'viewStore',
model : 'dataview_model',
data : [
{count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
]
});
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="count > 0">',
'<table class="view_table">',
'<tpl for="numbers">',
'<tr>',
'<td>{.}</td>',
'</tr>',
'</tpl>',
'</table>',
'</tpl>',
'</tpl>'
);
Ext.create('Ext.DataView', {
width : 500,
height : 200,
renderTo : Ext.getBody(),
store : Ext.getStore('viewStore'),
tpl : tpl
});
this is the working example which i have so far
/
what i want to do is stop the loop once there is 5 rows and add other values to second column like below
+----+ +----+
| | | |
+----+ +----+
+----+ +----+
| | | |
+----+ +----+
+----+
| |
+----+
+----+
| |
+----+
+----+
| |
+----+
any idea how to do this?
Thanks.
Im trying to loop a array with extjs xtemplate and create a table
Ext.define('dataview_model', {
extend : 'Ext.data.Model',
fields : [
{name: 'count', type: 'string'},
{name: 'maxcolumns', type: 'string'},
{name: 'maxrows', type: 'string'},
{name: 'numbers', type: 'array'}
]
});
Ext.create('Ext.data.Store', {
storeId : 'viewStore',
model : 'dataview_model',
data : [
{count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
]
});
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="count > 0">',
'<table class="view_table">',
'<tpl for="numbers">',
'<tr>',
'<td>{.}</td>',
'</tr>',
'</tpl>',
'</table>',
'</tpl>',
'</tpl>'
);
Ext.create('Ext.DataView', {
width : 500,
height : 200,
renderTo : Ext.getBody(),
store : Ext.getStore('viewStore'),
tpl : tpl
});
this is the working example which i have so far
http://jsfiddle/6HgCd/
what i want to do is stop the loop once there is 5 rows and add other values to second column like below
+----+ +----+
| | | |
+----+ +----+
+----+ +----+
| | | |
+----+ +----+
+----+
| |
+----+
+----+
| |
+----+
+----+
| |
+----+
any idea how to do this?
Thanks.
Share Improve this question asked Dec 26, 2011 at 11:58 Gihan LasitaGihan Lasita 3,05314 gold badges49 silver badges66 bronze badges 02 Answers
Reset to default 2I can't find a way to it with template only, but below is my solution which uses template and datachanged listener.
Ext.create('Ext.data.Store', {
storeId : 'viewStore',
model : 'dataview_model',
data : [
{count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']},
{count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
],
listeners: {
datachanged: function(store) {
store.data.each(function(record) {
record.data.groupedNumbers = [];
for (var i = 0, j = 0; i < record.data.count; ++i, j = i % record.data.maxrows) {
record.data.groupedNumbers[j] = record.data.groupedNumbers[j] || { row: j, numbers: [] };
record.data.groupedNumbers[j].numbers.push(record.data.numbers[i]);
}
});
}
}
});
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="count > 0">',
'<table class="view_table" style="border: 1px solid black">',
'<tpl for="groupedNumbers">',
'<tr>',
'<tpl for="numbers">',
'<td>{.}</td>',
'</tpl>',
'</tr>',
'</tpl>',
'</table>',
'</tpl>',
'</tpl>'
);
Working demo: http://jsfiddle/6HgCd/2/
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<table class="view_table">',
'<tr>',
'<tpl for="numbers">',
'<td>{.}</td>',
'<tpl if="xindex % 5 === 0">',
'</tr><tr>',
'</tpl>',
'</tpl>',
'</tr>',
'</table>',
'</tpl>'
);
http://jsfiddle/6HgCd/4/
本文标签: javascriptHow to loop inside extjs XTemplateStack Overflow
版权声明:本文标题:javascript - How to loop inside extjs XTemplate - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741893179a2403418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论