2

モジュールをロードするためにrequirejsを使用するWebアプリケーションがあります。Web アプリケーションは、どのデスクトップ ブラウザーでも問題なく動作します。また、Cordova でパッケージ化すると、iOS および Android でも動作します。ただし、Windows Phone 8 Cordova アプリケーションのビルド時には機能しません。

次のエラーが表示されます。

「ビューが見つかりません: パス「text!views/shell.html」経由で「views/shell」を検索しました

(デュランダル使用)

次のアプリケーション構造があります。

  • lib/require/require.js
  • www/app/viewmodels/shell.js
  • www/app/views/shell.html
  • www/app/main.js
  • www/index.html (行を含む: )
  • :

www/app/main.jsには次のコードが含まれています。

requirejs.config({
    //baseUrl: 'x-wmapp0:www/app',
    baseUrl: 'app',
    enforceDefine: true,
    paths: {
        'text': '../lib/require/text',
        'durandal':'../lib/durandal/js',
        'plugins' : '../lib/durandal/js/plugins',
        'transitions' : '../lib/durandal/js/transitions',
        'knockout': '../lib/knockout/knockout-2.3.0',
        'bootstrap': '../lib/bootstrap3/js/bootstrap',
        'jquery': '../lib/jquery/jquery-1.9.1',
        'modules' : 'modules'
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'],
            exports: 'jQuery'
       }
    }
});

define(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'bootstrap'],  function (system, app, viewLocator, bootstrap) {
    //>>excludeStart("build", true);
    system.debug(true);
    //>>excludeEnd("build");

    app.title = 'MyApp';

    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('viewmodels', 'views', 'views');

        //Show the app by setting the root view model for our application with a transition.
        app.setRoot('viewmodels/shell', 'entrance', 'applicationHost');
    });
});

このコードは、WP8 を除くすべてのデバイスで完全に機能します。baseUrl: 'x-wmapp0:www/app'という行を試して、WP8 Cordova が内部的に使用する実際のパスを設定しましたが、うまくいきません。「/」やhttpで始まるパスではないからでしょうか。

requirejsを使用してモジュールとビューをロードできるようにrequirejsを構成する方法についてのアイデアはありますか?

4

3 に答える 3

6

これがあなたに役立つかどうかを確認してください http://mikaelkoskinen.net/durandal-phonegap-windows-phone-8-tutorial/

また、2013 年 10 月 18 日の時点で、Phonegap Build は WP8 のベータ サポートを追加しました。「winphone: を gap:platform として追加し、phonegap 3.0 を使用していることを確認します。現在のところうまくいきませんが、使用できるかもしれません。

于 2013-10-22T13:55:49.853 に答える
0

cordovalib/XHRHelper.cs の HandleCommand メソッドにブレークポイントを設定して、何が起こっているかを確認することをお勧めします。また、HandleCommand の次のバージョンは、より適切に機能する可能性があります

    public bool HandleCommand(string commandStr)
    {
        if (commandStr.IndexOf("XHRLOCAL") == 0)
        {
            string url = commandStr.Replace("XHRLOCAL/", "");

            Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);

            try
            {

                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (isoFile.FileExists(uri.AbsolutePath))
                    {
                        using (
                            TextReader reader =
                                new StreamReader(isoFile.OpenFile(uri.AbsolutePath, FileMode.Open, FileAccess.Read))
                            )
                        {
                            string text = reader.ReadToEnd();
                            Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
                            return true;
                        }
                    }
                }

                url = uri.AbsolutePath;
            }
            catch { }

            var resource = Application.GetResourceStream(new Uri(url, UriKind.Relative)) ??
                // for relative paths and app resources we need to add www folder manually
                // there are many related issues on stackoverflow + some prev worked sample don't because of this
                Application.GetResourceStream(new Uri("www/" + url, UriKind.Relative));

            if (resource == null)
            {
                // 404 ? 
                Browser.InvokeScript("__onXHRLocalCallback", new string[] { "404" });
                return true;
            }
            else
            {
                using (StreamReader streamReader = new StreamReader(resource.Stream))
                {
                    string text = streamReader.ReadToEnd();
                    Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
                    return true;
                }
            }
        }

        return false;
    }
于 2013-11-05T19:07:25.190 に答える