2013-03-21 108 views
1

如何在Sencha Touch視圖中使用JS?Sencha Touch 2 - 將javascript添加到視圖

Ext.define('project.view.viewexample', { 
extend: 'Ext.Panel', 
xtype: 'asd', 

config: { 
    styleHtmlContent: true, 
    scrollabe: 'vertical', 
    title: 'TITLE!', 
    Html: '<html>code and also JS?' 
} 
}); 

我有htmlcode,其中包括jscode(腳本標籤內)。在這個問題上似乎沒有用,我說得對嗎?我也試過使用tpl,但它不會改變任何東西。

任何人都知道如何正確使用JS?一個更好的選擇是在控制器內使用它,但在那種情況下,我不知道如何傳遞數據。

編輯: 我已經有點接近我認爲的解決方案。下面這段代碼顯然是錯誤的,但也許有人可以看到我在做什麼錯:

Ext.define('projext.view.viewexample', { 
extend: 'Ext.Panel', 
xtype: 'gps', 

config: { 
    styleHtmlContent: true, 
    scrollabe: 'vertical', 
    title: 'GPS', 
    tpl: 'Här var det GPS' 
}, 
constructor: function() { 
    this.getPosition(); 
}, 
getPosition: function() { 
    var geo = Ext.create('Ext.util.Geolocation', { 
     autoUpdate: false, 
     listeners: { 
      locationupdate: function(geo) { 
       alert('New latitude: ' + geo.getLatitude()); 
      }, 
      locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) { 
       if(bTimeout){ 
        alert('Timeout occurred.'); 
       } else { 
        alert('Error occurred.'); 
       } 
      } 
     } 
    }); 
    geo.updateLocation(); 
} 
}); 

回答

1

html配置必須是小寫。

Ext.define('project.view.viewexample', { 
    extend: 'Ext.Panel', 

    styleHtmlContent: true, 
    scrollabe: 'vertical', 
    title: 'TITLE!', 
    html: 'define your html' 
}); 
+0

謝謝,我不知道。但是,它不是我的問題的答案,我在哪裏放置我的jscode? – Thomas 2013-03-22 07:21:35

+0

什麼樣的JsCode?你更新了你的OP,這是一個很好的例子。請注意,您需要在這一行中使用'this'關鍵字:'constructor:function(){this.getPosition();},' – A1rPun 2013-03-22 11:53:48

+0

我試圖添加「this」。在構造函數中的方法調用之前。但是我得到「ncaught ReferenceError:getPosition沒有定義」。你知道爲什麼嗎? – Thomas 2013-03-25 15:27:57