2013-10-29 20 views
1

我剛開始用durandal來試用android應用程序開發。這也是我第一次嘗試應用程序開發。使用durandal創建一個android應用程序

我正在通過docs使用含羞草,並沒有按預期鍛鍊。

步驟覆蓋從迪朗達爾

  • 下載起動套件。
  • 執行mimosa build -mo並得到main-built.js
  • 將資產中的所有文件複製到phonegap示例項目中。
  • 包含在phonegap項目的index.html中的main-built.js路徑。

什麼都改變我index.html中做出

目前,它看起來像

<html> 
    <head> 
     <meta charset="utf-8" /> 
     <meta name="format-detection" content="telephone=no" /> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
     <link rel="stylesheet" type="text/css" href="css/index.css" /> 
     <link rel="stylesheet" type="text/css" href="css/styles.css" /> 
     <title>Hello World</title> 
    </head> 
    <body> 
     <div class="app"> 
      <h1>PhoneGap</h1> 
      <div id="deviceready" class="blink"> 
       <p class="event listening">Connecting to Device</p> 
       <p class="event received">Device is Ready</p> 
      </div> 
     </div> 
     <script type="text/javascript" src="phonegap.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
     <script type="text/javascript" src="js/main-built.js"></script> 
     <script type="text/javascript"> 
      app.initialize(); 
     </script> 
    </body> 
</html> 

我需要做的,使迪朗達爾的初學者工具包爲Android的所有更改應用程序嗎?

+0

大問題..關於這個Durandaljs文檔是很小:(想用韋蘭得到這個小狗在PhoneGap的運行也建立 上的任何進步!這個? – EeKay

+0

我複製了http:// durandaljs中的示例。com/version/latest/HTML%20Samples.zip並將這些文件複製到phonegap樣本中,幷包含我複製的所有js,然後我在durandal網站中執行步驟,示例應用程序開始工作。但是在使用ajax調用的情況下卡住了 – Okky

+0

謝謝,我很快就會檢查 – EeKay

回答

1

我已經爲android和ios做了一些Durandal/Phonegap的應用程序,我自己也走過了這條路,這並不好笑,但我離題了。 您的index.html中的第一個app.initialize()是NO-NO。絕對不是這裏的路。你想要做的就是讓你的索引看看durandal是如何喜歡的 - 清空所有javascript !. phonegap.js是個例外,你需要直接在你的index.html中引用它。我還沒有成功地計算出異步加載和初始化cordova,但是有一些資源在那裏。

所有的魔法都會像你在main.js中所期待的那樣發生,你顯然會在你用mimosa或weyland構建之前做到這一點。見下面

define(['durandal/system', 'durandal/app', 'durandal/viewLocator'], 

function (system, app, viewLocator) { 

    document.addEventListener('deviceready', function(){ setTimeout(onDeviceReady, 500); }, false); 

    function onDeviceReady(){ 
    app.title = 'My App'; 

    app.configurePlugins({ 
     router: true, 
     dialog: true, 
     widget: true 
    }); 


    app.start().then(function() { 
     //Replace 'viewmodels' in the moduleId with 'views' to locate the view. 
     //Look for partial views in a 'views' folder in the root. 
     viewLocator.useConvention(); 

     app.setRoot('viewmodels/shell', 'entrance'); 
    }); 
    }; 
}); 

我的setTimeout 1/2秒等待科爾多瓦做的業務調用函數之前,我有幾個問題不一致,否則。 將main.js重寫爲AMD模塊並將其注入到shell中。然後可以在shell.js中調用app.initialize或activateComponentComplete。

GOTCHA#1

你可能會不經意地來到另一個問題,這讓我幾乎撕碎了我的頭髮掉了很多天在Android平臺上工作時。當你在你的視圖中做鏈接時,你可能會試圖做<a href="#somewhere">Go Somewhere</a> Android不喜歡這樣,它只是在logcat中發出亂碼。你最好做這個<a data-bind="click:goSomewhere">Go Somewhere</a>,然後在你的模型上定義一個使用router.navigate的函數。

我希望這可以幫助你。

0

就解決了這個問題,TTS爲:

app.speakText = function (textToSpeak) { 
    if (window.cordova) { 
     var deferred = $.Deferred(); 
     window.TTS.speak({ 
      text: textToSpeak, 
      locale: 'en-US', 
      rate: 0.75 
     }, function() { 
      deferred.resolve(true); 
     }, function (reason) { 
     }); 
     return deferred.promise(); 
    } 
}; 
相關問題