javascript - how to repeat tpl blocks inside tpl -
javascript - how to repeat tpl blocks inside tpl -
i have boxcomponent i'm creating tpl. in inittemplate set template want doing
this.tpl = new ext.xtemplate( my_template ). so in my_template, bit long actually, have block wish repeat more 1 time within my_template. what's best way accomplish that? wish didn't have re-create block on , over, specially if block long.
for example, let's my_template =
'<tpl for="value1">', '<div class="c1">{a}</div>', '<div class="c2">{b}</div>', '</tpl>' '<tpl for="value2">', '<div class="c1">{a}</div>', '<div class="c2">{b}</div>', '</tpl>' my info looks like:
data = { value1: { a: 'blah', b: 'bleh' } value2: { a: 'bloh', b: 'bluh' } } so, in example, i'd know if there's way sort of phone call function repeat
'<div class="c1">{a}</div>', '<div class="c2">{b}</div>', so i'd have
'<tpl for="value1">', myfunction(); '</tpl>' '<tpl for="value2">', myfunction(); '</tpl>'
now exclusively different question, after have edited it. nevermind, reply yes, can utilize fellow member functions generate content. illustration xtemplate docs. can see, returned isbaby , isgirl methods below rendered in resulting html. need set myfunction , phone call within template: this.myfunction()
var tpl = new ext.xtemplate( '<p>name: {name}</p>', '<p>kids: ', '<tpl for="kids">', '<tpl if="this.isgirl(name)">', '<p>girl: {name} - {age}</p>', '<tpl else>', '<p>boy: {name} - {age}</p>', '</tpl>', '<tpl if="this.isbaby(age)">', '<p>{name} baby!</p>', '</tpl>', '</tpl></p>', { // xtemplate configuration: disableformats: true, // fellow member functions: isgirl: function(name){ homecoming name == 'aubrey' || name == 'nikol'; }, isbaby: function(age){ homecoming age < 1; } } ); tpl.overwrite(panel.body, data); and data:
var info = { name: 'don griffin', title: 'senior technomage', company: 'sencha inc.', drinks: ['coffee', 'water', 'more coffee'], kids: [ { name: 'aubrey', age: 17 }, { name: 'joshua', age: 13 }, { name: 'cale', age: 10 }, { name: 'nikol', age: 5 }, { name: 'solomon', age: 0 } ] }; javascript extjs extjs3
Comments
Post a Comment