-
17 Jun 2011 11:28 AM #1
Calling a function inside a tpl [ ]
Calling a function inside a tpl [ ]
Hi - I'm new to Sencha touch and I'm trying to modify a twitter example I found online in order to turn urls from a twitter feed into clickable links. I saw that one of the examples in the sencha touch library uses a linkify feature, but I can't figure out how to incorporate it into my own project. Here's my code:
and here's the error I get:Code:t_news = new Ext.Component({ cls:'t_news', title:'News', scroll: 'vertical', tpl: [ '<tpl for=".">', '<div class="tweet">', '<div class="avatar"><img src="{profile_image_url}" /></div>', '<div class="tweet-content">', '<h2>{from_user}</h2>', '<p>{text:this.linkify}</p>', '</div>', '</div>', '</tpl>', ] }); function linkify(value){ return value.replace(/(http:\/\/[^\s]*)/g, "<a target=\"_blank\" href=\"$1\">$1</a>"); }
Code:Uncaught TypeError: Object [object Object] has no method 'linkify'
-
16 Dec 2011 3:53 AM #2
use {[... ]}
use {[... ]}
Here is a sample code,
hope it helps.
Code:var sbTpl = new Ext.XTemplate('<tpl for=".">', '<div class="sb-section-title">{title}</div>', '<div class="sb-section-score">{correct} of {total} Correct ( {[getPercent(values.correct,values.total)]} %)</div>', '</tpl>');
" You can add any javascript code inside {[ ... ]}"Last edited by gaurav.k; 16 Dec 2011 at 3:54 AM. Reason: typographical mistake
-
16 Dec 2011 4:46 AM #3Sencha - Community Support Team
- Join Date
- Nov 2007
- Location
- Helsingborg, Sweden
- Posts
- 2,460
- Vote Rating
- 56
Linkify needs to be defined on the template itself, not on the class.
Code:tpl: [ '<tpl for=".">', '<div class="tweet">', '<div class="avatar"><img src="{profile_image_url}" /></div>', '<div class="tweet-content">', '<h2>{from_user}</h2>', '<p>text:{[this.linkify(values.text)]}</p>', '</div>', '</div>', '</tpl>', { linkify : function (value){ return value.replace(/(http:\/\/[^\s]*)/g, "<a target=\"_blank\" href=\"$1\">$1</a>"); } } ] });


Reply With Quote