2010-12-28 17 views
5

एक्सटी जेएस में मैं चाहता हूं कि मेरे कुछ बटन लिंक की तरह काम करें (यानी <a href...)।एक्सटी जेएस: बटन को एक लिंक बनाएं

मैं यह कैसे कर सकता हूं।

अभी मैं एक हैंडलर जोड़ रहा हूं जो window.location.href=http://.... करता है।

लेकिन मैंने सोचा कि एक आसान तरीका होना चाहिए - मेनू आइटम में जैसे href विशेषता जोड़ने जैसा कुछ।

कुछ विचार?

+0

जहां तक ​​मुझे पता है, वैसे ही यह वास्तव में किया जाना चाहिए। – Mchl

+0

ExtJS आधुनिक 6.x (6.5) के लिए https://stackoverflow.com/questions/47494458/extjs-6-x-modern-button-as-a-link/47519792#47519792 –

उत्तर

3

एक मौजूदा user extension भी है जो वास्तव में ऐसा करता है।

7

कि जिस तरह से यह किया है ... अधिक पोर्टेबल आप Ext.ux.LinkButton में Ext.Button (या जो भी) का विस्तार कर सकता है और संपत्ति और इस विस्तारित वर्ग में आवश्यक व्यवहार (सिर्फ एक quick- & -dirty उदाहरण) को लागू होने के लिए:

Ext.ux.LinkButton = Ext.extend(Ext.Button, { 
    href: null, 
    handler: function() { 
     if (this.href) { 
      window.location.href = this.href; 
     } 
    } 
}); 
Ext.reg("ux-linkbutton", Ext.ux.LinkButton); 

var btn = new Ext.ux.LinkButton({ 
    text: "Link to Google", 
    href: "http://www.google.com" 
}); 

संपादित करें:

उपस्थिति के सरल परिवर्तन:

Ext.ux.LinkButton = Ext.extend(Ext.Button, { 
    href: null, 
    template: new Ext.Template(
     ['<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">', 
     '<tr><td class="x-btn-tl"><i>&#160;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&#160;</i></td></tr>', 
     '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><a href="{0}"></a></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>', 
     '<tr><td class="x-btn-bl"><i>&#160;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&#160;</i></td></tr>', 
     '</tbody></table>'], {compiled: true}), 
    buttonSelector : 'a:first-child', 
    getTemplateArgs : function(){ 
     return [this.href, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id]; 
    }, 
    handler: function(b, e) { 
     if (this.href) { 
      e.stopEvent(); 
      window.location.href = this.href; 
     } 
    } 
}); 
+0

धन्यवाद। यह मेनू आइटम में क्यों नहीं हो सकता है (इसलिए जब उपयोगकर्ता गुजरता है तो वह देख सकता है कि लिंक उसे स्टेटस बार में कहाँ ले जाएगा) – flybywire

+0

यह ExtJS 4 में काम नहीं करता है; क्या इसे ExtJS4 में काम करने के लिए संशोधित करना मुश्किल होगा? –

संबंधित मुद्दे