2013-09-26 17 views
0

如果這個問題很簡單,但我沒有找到辦法做到這一點,我真的很新的這個Java腳本和Sencha觸摸很抱歉。HTML與函數的值

我有一個函數返回一個值。 現在我想顯示一個html行內的函數的值。

如何從html元素調用此函數?我如何顯示價值?

config: { 
     title: 'Me', 
     iconCls: 'user', 
     //layout: 'fit', 
     /* create a title bar for the tab panel */ 
     items: [ 
      { 
      docked: 'top', 
      xtype: 'titlebar', 
      title: 'Singers' 
     }, 
      { 
      html: [ 
         '<h1>Hi!! ' + this.setName +'</h1>' 
        ].join("") 

    } 
     ], 

}, 
setName: function (val) { 
    var store =Ext.getStore('user'); 
    var last = st.last('user'); 
    return val=(last.get('user')); 
} 
}); 
+0

添加[處理](http://try.sencha.com/extjs/4.1.0/demos/Ext.Button.handler.1/)到您的按鈕。 – DarkBee

+0

但我希望這出現在HTML ...沒有按鈕 –

+0

只是爲了顯示你好+(返回值) –

回答

0

你可以使用的itemId屬性引用的組件,然後更新通過INITIALISE收聽它的HTML屬性。

例如:

config: { 
     title: 'Me', 
     iconCls: 'user', 
     //layout: 'fit', 
     /* create a title bar for the tab panel */ 
     items: [ 
      { 
       docked: 'top', 
       xtype: 'titlebar', 
       title: 'Singers' 
      }, 
      { 
       itemId:'htmlContainer', //use itemIds like div ids 
       xtype:'container', 
       html: '' 
      } 
     ], 

     /** 
     * @cfg listeners 
     * Parent Component listeners go here. 
     * Check sencha touch doc for more information and other available events. 
     */ 
     listeners:{ 
      initialize: 'onInitialise' 
     } 

}, 

onInitialise: function() 
{ 
     //set the html config item here 
     var c = this.down('#htmlContainer'); 
     c.setHtml(this.setName()); 
}, 
setName: function (val) { 
    .... 
}