0

私は徐々にこれに必死になっています。RequireJS を使用して JS コードを分離するプロジェクトがあります。私はなんとかこれを起動して実行しましたが、今はiscrollviewライブラリに問題があります。これにより、jQuery Mobile Web サイトで使用するiScrollの実装が提供されます。私の状況をスケッチするコードは次のとおりです。

index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>iscrollview</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="js/lib/jquery-mobile/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" type="text/css" href="js/lib/iscrollview/iscrollview.css" />
        <script type="text/javascript" data-main="js/main.js" src="js/lib/require/require-2.1.1.min.js"></script>
    </head>

    <body>
        <div data-role="page">

            <div data-role="header">
                <h1>Header</h1>
            </div>

            <div data-role="content">
                <div data-iscroll>
                    <!-- this contains some long content (long enough to trigger scrolling) -->
                </div>
            </div>

            <div data-role="footer">
                <h2>Footer</h2>
            </div>

        </div>
    </body>
</html>

js/main.js:

requirejs.config({
    baseUrl: 'js',
    paths: {
        jquery: 'lib/jquery/jquery-1.8.2.min',
        jquerymobile: 'lib/jquery-mobile/jquery.mobile-1.2.0.min',
        iscroll: 'lib/iscroll/iscroll',
        iscrollview: 'lib/iscrollview/iscrollview'
    },
    shim: {
        jquerymobile: {
            deps: ['jquery']
        },
        iscroll: {
            deps: ['jquerymobile']
        },
        iscrollview: {
            deps: ['iscroll']
        }
    }
});

requirejs(['jquery','jquerymobile','iscroll','iscrollview'], function($){

    /* I would expect that the correct JS files are loaded by the time we get here,
       so the iscrollview.js should recognize the data-trim attribute which I've applied
       earlier in index.html but unfortunately this doesn't happen in this implementation. /*

});

皆さんが外出できるように、私の問題を十分に指摘できたことを願っています。あなたがそれに費やした努力に本当に感謝します!

編集:

(簡略化された)プロジェクトはこちらにあります

4

1 に答える 1

3

あなたの .zip プロジェクトを見た後、私はついに答えを見つけました。iscrollview.js は自己初期化されており、iscrollview.js ファイルの 1839 行で確認できます。自己初期化は、require.js がファイルに読み込まれたときに、明らかに既に発生している「pagecreate」イベントに依存します。 したがって、解決策は、自分で isscrollview を初期化することです

requirejs.config({
    baseUrl: 'js',
    paths: {
        jquery: 'lib/jquery/jquery-1.8.2.min',
        jquerymobile: 'lib/jquery-mobile/jquery.mobile-1.2.0.min',
        iscroll: 'lib/iscroll/iscroll',
        iscrollview: 'lib/iscrollview/iscrollview'
    },
    shim: {
        jquerymobile: {
            deps: ['jquery']
        },
        iscroll: {
            deps: ['jquerymobile']
        },
        iscrollview: {
            deps: ['iscroll']
        }
    }
});

requirejs(['jquery','iscroll','jquerymobile','iscrollview'], function($, iScroll){
    var elements = jQuery(document).find(":jqmData(iscroll)");
    elements.iscrollview();
});
于 2012-11-26T08:41:57.963 に答える