PDA

View Full Version : JsonView + MasterTemplate looping



nassaja-rus
19 Jun 2007, 7:27 AM
I extended basic Ext classes (src/widgets/View.js, src/widgets/JsonView.js, src/core/Template.js, ) for Mastertemplate looping support. This support autofill subtemplate from json data too.

This is diff for them:

/src/widgets/View.js (http://foto.za.ru/js/ext-1.1-beta1/source/widgets/View2.js):


39c39
< tpl = new Ext.Template(tpl);
---
> tpl = new Ext.MasterTemplate(tpl);


/src/widgets/JsonView.js (http://foto.za.ru/js/ext-1.1-beta1/source/widgets/JsonView2.js):


94c94
< html[html.length] = this.tpl.apply(data);
---
> html[html.length] = this.tpl.apply(data, i+1);
173c173
< return this.jsonData[this.indexOf(node)] || null;
---
> return this.tpl.dataMapping[this.indexOf(node)+1]|| null;


/src/core/Template.js (http://foto.za.ru/js/ext-1.1-beta1/source/core/Template2.js):



248a31,34
>
> this.allIndex = 1;
> this.dataMapping = [];
>
309c95,97
< this.add(name, values[i]);
---
> this.dataMapping[this.allIndex] = values[i];
> this.allIndex++;
> this.add(name, values[i]);
326c114
< applyTemplate : function(values){
---
> applyTemplate : function(values, index){
327a116,123
>
> this.dataMapping[this.allIndex] = values;
> this.allIndex++;
>
> for(var i = 0; i < this.subCount; i++){
> this.fill(s[i].name, values[s[i].name], true);
> }



Demo there: http://foto.za.ru/test/

I hope it it will be useful, I wait for your remarks.