1

我昨天刚开始使用 durandal 来尝试 android 应用程序开发。这也是我第一次尝试应用程序开发。

我正在使用含羞草浏览文档,但它没有按预期锻炼。

涵盖的步骤

  • 从 durandal 下载的入门套件。
  • 执行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>

我需要做哪些更改才能将 durandal 的入门工具包制作为 Android 应用程序?

4

2 回答 2

1

我已经用 Durandal/Phonegap 为 android 和 ios 做了一些应用程序,我自己也走过这条路,这并不好笑,但我离题了。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');
    });
   };
});

在调用该函数之前,我设置了 1/2 秒以等待科尔多瓦完成它的业务,否则我有一些不一致的问题。将您的 main.js 重写为 AMD 模块并将其注入 shell。然后,您可以从 shell.js 中的 activate 或 compositionComplete 调用 app.initialize。

问题 #1

在安卓平台上工作时,你可能无意中遇到了另一个问题,这让我好几天都差点把头发扯掉。当你在你的视图中做链接时,你可能会想要做<a href="#somewhere">Go Somewhere</a>Android 不喜欢这样,它只会在 logcat 中喷出大量的乱码。你最好这样做<a data-bind="click:goSomewhere">Go Somewhere</a>,然后在你的模型上定义一个使用 router.navigate 的函数。

我希望这能够帮到你。

于 2013-12-31T10:47:50.997 回答
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();
    }
};
于 2017-07-24T04:46:14.033 回答