2013年10月23日 星期三

Extjs 4 使用 google speech api



想要在自行開發的網頁上能使用 google speech api 的話,input 要加上 x-webkit-speec 和 speech,
那如果使用 Extjs上要如何作呢。

因為我是使用 Extjs MVC,所以原本要在 Controller上加上 render function,但都沒有作用,所以還是把 render移回到 view上,程式碼如下

View :原本程式碼加上 listener

xtype: 'textfield',
,renderTo: Ext.getBody()
,listeners:: {
    render: function(cmp) {
cmp.el.dom.firstChild.firstChild.lastChild.firstChild.setAttribute("x-webkit-speech","x-webkit-speech");
cmp.el.dom.firstChild.firstChild.lastChild.firstChild.setAttribute("speech","speech");
     }

}

Controller: 加上 webkitspeechchange function

init: function() {
    this.control({
               'tellist textfield[name=param]' :{
        
            /* for google speech api*/
                    ,webkitspeechchange: function(fld,e) {
       
        this.doFetchTel();
                   }
     
                 }

    });  
     
}

這樣應該就可以使用了