1. #1
    Sencha User mynsa04's Avatar
    Join Date
    Dec 2008
    Posts
    15
    Answers
    1
    Vote Rating
    0
    mynsa04 is on a distinguished road

      0  

    Default Answered: How to put JSON to attribute from XTemplate?

    Answered: How to put JSON to attribute from XTemplate?


    Code:
    data = {
        project_id: 2,
        project_name: 'Project name',
        project_start_dt: '2012-05-03',
        project_type: 'super-type',
        project_status: 'super-status',
        ...
    }
    
    data.json_data = Ext.encode(data);
    
    headerTpl = new Ext.XTemplate(
        '<h1>{project_name} <a class="b-project__edit-link" href="#" onclick="return {json_data}">edit</a></h1>'
    );
    
    headerTpl.overwrite(Ext.getBody(), data);
    Sorry for my english ).

    I need to put data to h1/a/@onclick, because, when i execute dom.onclick() in JS, i have ready Object with all my data. How can i do that?

  2. I find the solution:
    Code:
    Ext.Tpl.Comment = new Ext.XTemplate(
        '<div class="b-comment" onclick="return({[this.getOnclick(values)]});">'
            ,'bla bla...'
        ,'</table>'
    
        ,{
            getOnclick: function(values) {
                var copy = {};
                Ext.apply( copy, values );
                delete copy.comment_body; // delete specific values
                var ret = Ext.encode( copy ).replace(/\"/g, "'");
                return ret;
            }
        }
    );
    Then, when i run something like that: el.down('.b-comment').dom.onclick(), the result is Object.

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,895
    Answers
    368
    Vote Rating
    176
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    Code:
    data = {
        project_id: 2,
        project_name: 'Project name',
        project_start_dt: '2012-05-03',
        project_type: 'super-type',
        project_status: 'super-status',
        ...
    }
    
    
    headerTpl = new Ext.XTemplate(
        '<h1>{project_name}</h1>'
    );
    
    
    Ext.getBody().on({
    	click: function () {
    		headerTpl.overwrite(Ext.getBody(), data);
    	}
    	, single: true
    });
    Does this work?

  4. #3
    Sencha User mynsa04's Avatar
    Join Date
    Dec 2008
    Posts
    15
    Answers
    1
    Vote Rating
    0
    mynsa04 is on a distinguished road

      0  

    Default


    No, sorry. I need to put json in onclick, not apply template by click. Something like this:
    Code:
    headerTpl = new Ext.XTemplate(     '<h1>{project_name} <a class="b-project__edit-link" href="#" onclick="return ({project_id: {project_id}, project_name: \'{project_name}\', ...})">edit</a></h1>' );
    but automaticaly, just put encoded object, without enumerate all keys by hands.

  5. #4
    Sencha User mynsa04's Avatar
    Join Date
    Dec 2008
    Posts
    15
    Answers
    1
    Vote Rating
    0
    mynsa04 is on a distinguished road

      0  

    Default


    I find the solution:
    Code:
    Ext.Tpl.Comment = new Ext.XTemplate(
        '<div class="b-comment" onclick="return({[this.getOnclick(values)]});">'
            ,'bla bla...'
        ,'</table>'
    
        ,{
            getOnclick: function(values) {
                var copy = {};
                Ext.apply( copy, values );
                delete copy.comment_body; // delete specific values
                var ret = Ext.encode( copy ).replace(/\"/g, "'");
                return ret;
            }
        }
    );
    Then, when i run something like that: el.down('.b-comment').dom.onclick(), the result is Object.

Thread Participants: 1

Tags for this Thread

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