1. #1
    Ext User
    Join Date
    Jan 2011
    Posts
    6
    Vote Rating
    0
    rmitchell62@me.com is on a distinguished road

      0  

    Default XTemplate access global variable or js function from within 'if='?

    XTemplate access global variable or js function from within 'if='?


    I'm trying to make the following, which seems like it would be pretty comment.

    a select 'dropdown' (eg. select one of 'apple' 'orange' 'pear') and

    a templated panel that lists attributes of the selected fruit.

    So, I want to be able to only show the attributes for 'apple', when 'apple' is selected from the dropdown.

    A template fills in the dropdown just fine. A second template can display the attributes data for all fruits. I am trying to limit this to the selected fruit.

    eg. <tpl for="fruit">
    <tpl if="name= &quot;apple&quot;">
    <div>This fruit is {colour}</div>
    </tpl></tpl>

    works fine. However I don't want to compare to a static string I need to fetch the value from the select. I've
    tried many combinations. For instance I create a variable outside of the template
    var this.selectedFruit = "apple";

    and inside the template:
    <tpl if="name== this.selectedFruit">
    but no go. I've tried every permutation of escaping and quoting I can think of. Is there any way to read a variable (that isn't part of the template data) from within the template? How might I read a global var, or call a javascript function or query a ui element value? ( I've tried [{...}] to no avail - is this supposed to work from inside an 'if='?

    Please, please, please improve the documentation and provide more thorough examples for XTemplate because it is very powerful. Flailing around trying to guess the syntax is a slow and frustrating process.

  2. #2
    Sencha User
    Join Date
    Mar 2011
    Posts
    38
    Vote Rating
    0
    ssk_hari is on a distinguished road

      0  

    Default


    Did you found the solution for this ?? Am also facing the similar scnario ...

  3. #3
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    var odd = 1;
    Code:
    <tpl if="xindex == [odd]">{[odd]} Found Here</tpl>
    Can you try this, it seems to work.

  4. #4
    Sencha User
    Join Date
    Mar 2011
    Posts
    38
    Vote Rating
    0
    ssk_hari is on a distinguished road

      0  

    Default


    But, how can I declare a variable like it in Sencha ? ... Also, while looping in tpi, I have to access a javascript function or increment a global variable ... how to do that ?

  5. #5
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      1  

    Default


    You can call external function from template like this.

    Code:
    function test(){
        return 'return me';
     }
    
    <tpl if="xindex == [odd]">{[odd]} Found Here returned  {[test()]}</tpl>
    Regarding variable, can you provide a test case to look into.

  6. #6
    Sencha User
    Join Date
    Mar 2011
    Posts
    38
    Vote Rating
    0
    ssk_hari is on a distinguished road

      0  

    Default


    This is my requirement. I have a JSON, (say it contains an array of states and country).. I have to display each country and respective states ... So, when parsing , I have to display the COUNTRY name in Heading .. say . red color .. Now, when parsing how can I know when the country name is getting changed ??

    Normal cases, when looping we assign the country name to local variable while looping ... and then when we get a new value we compare to the local value ... when they are not same, we can assume that the country name has changed .. But how to implement this in sencha ??

    Your above code is really coool .. I can use it !! ...

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Posts
    18
    Vote Rating
    0
    RyanFreng is on a distinguished road

      0  

    Default


    I'm trying to do the same thing... but can't access a function outside of the XTemplate object...

    Code:
    catalogTpl: new Ext.XTemplate([
              '<div class="search-web x-panel-body x-html">',
              '<div class="x-content">',
                '<ol>',
                  '<tpl for=".">',
                  '<li>',
                    '<div class="catalog-title"><a href="{url}">{title}</a></div>',
                    '<div class="catalog-author">By <span>{author}</span></div>', 
                    '<div class="catalog-type">{[getDTF(values.document_types_facet)]}</div>',
                    '<tpl if="dates">',
                    '<div class="catalog-date">Dates <span>{[values.dates.join(",")]}</span></div>',
                    '</tpl>',
                    '<tpl if="this.getDescription(location_holdings_codes)">',
                    '<div class="catalog-description">{[this.getDescription(location_holdings_codes)]}</div>',                
                    '</tpl>',
                  '</li>',
                  '</tpl>',
                '</ol>',
              '</div>',
              '</div>'
        ])
    I need the data being passed to my template to get some special formatting done by the 'getDTF' function. How do we call a function outside of the template? {[theFunction()]} just returns 'Uncaught ReferenceError: theFunction is not definted.

  8. #8
    Sencha User
    Join Date
    Feb 2011
    Posts
    18
    Vote Rating
    0
    RyanFreng is on a distinguished road

      0  

    Default Is a solution a solution if it's ugly?

    Is a solution a solution if it's ugly?


    Here's what I came up with. I needed to iterate over the array 'document_types_facet' and change the image based on the item. From what I can tell, there is NO WAY for you to call a function from inside a template. You can ONLY call a local function, configured inside your template, that has a boolean response from a 'tpl if' block. No amount of "{[]}" will let you call functions.

    Here's the data I have:
    Code:
    {"document_types_facet" => ["Books", "Microforms"]}
    And the ugly but functioning solution:
    Code:
                    '<tpl for="document_types_facet">',
                    '{[values == "Books" ? "<img src=images/book.png />" : ""]}',
                    '{[values == "Electronic Resources" ? "<img src=images/www.png />" : ""]}',
                    '{[values == "Microforms" ? "<img src=images/film.png />" : ""]}',
                    ...
                    '{[values == "Mixed Materials" ? "<img src=images/shape_move_front.png />" : ""]}',
                    '{.} ',
                    '</tpl>',
    It looks like Ext JS expects your data to be perfect by the time it gets to a template. Templates seem pretty bad at handling the objects they works with.

Similar Threads

  1. unable to access variable defined outside Jsonstore in side XTemplate
    By ranjay in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 26 Jan 2011, 9:50 AM
  2. Access global variable value inside render function
    By funwithextjs in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 10 Dec 2010, 1:20 PM
  3. DD constrainTo() access sets global variable
    By gutorb4 in forum Community Discussion
    Replies: 4
    Last Post: 6 Sep 2007, 8:12 AM

Thread Participants: 3

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi