6

私は、それぞれにいくつかのページがあるさまざまな領域を持つSPAを使用しています。私の上司は、それぞれにいくつかのアイテムを含む多数のビューとビューモデル フォルダーを本当に望んでいません。次のようなものを使用するように Durandal を構成するにはどうすればよいですか。

/App/Areas/Login/
                 login.html
                 login.js
/App/Areas/Here/
                 subpage1.html
                 subpage1.js
                 subpage2.html
                 subpage2.js
                 subpage3.html
                 subpage3.js
/App/Areas/There/
                 subpage1.html
                 subpage1.js
                 subpage2.html
                 subpage2.js
                 subpage3.html
                 subpage3.js

エリアに関する他の同様の質問を見てきましたが、開始方法がよくわかりません。ありがとう。

4

2 に答える 2

5

Durandal 2.0 に同梱されている「samples」プロジェクトは、ルーターをカスタマイズせずに目的を達成する方法の例です。以下の例はそのプロジェクトのものです (また、「子」ルーターの使用方法も示しています)。「makeRelative」の呼び出しの moduleId パラメーターとルート構成を組み合わせて、必要なフォルダー構造を提供する方法に注目してください。

app/ko/index.js

define(['plugins/router', 'knockout'], function(router, ko) {
var childRouter = router.createChildRouter()
    .makeRelative({
        moduleId:'ko',
        fromParent:true
    }).map([
        { route: '',                moduleId: 'helloWorld/index',       title: 'Hello World',           type: 'intro' },
        { route: 'helloWorld',      moduleId: 'helloWorld/index',       title: 'Hello World',           type: 'intro',      nav: 5},
        { route: 'clickCounter',    moduleId: 'clickCounter/index',     title: 'Click Counter',         type: 'intro',      nav: 4},
        { route: 'simpleList',      moduleId: 'simpleList/index',       title: 'Simple List',           type: 'intro',      nav: 3 },
        { route: 'betterList',      moduleId: 'betterList/index',       title: 'Better List',           type: 'intro',      nav: 2},
        { route: 'controlTypes',    moduleId: 'controlTypes/index',     title: 'Control Types',         type: 'intro',      nav: 1 },
        { route: 'collections',     moduleId: 'collections/index',      title: 'Collection',            type: 'intro' ,     nav: 99 },
        { route: 'pagedGrid',       moduleId: 'pagedGrid/index',        title: 'Paged Grid',            type: 'intro',      nav: 98 },
        { route: 'animatedTrans',   moduleId: 'animatedTrans/index',    title: 'Animated Transition',   type: 'intro',      nav: true },
        { route: 'contactsEditor',  moduleId: 'contactsEditor/index',   title: 'Contacts Editor',       type: 'detailed',   nav: true },
        { route: 'gridEditor',      moduleId: 'gridEditor/index',       title: 'Grid Editor',           type: 'detailed',   nav: true },
        { route: 'shoppingCart',    moduleId: 'shoppingCart/index',     title: 'Shopping Cart',         type: 'detailed',   nav: true },
        { route: 'twitterClient',   moduleId: 'twitterClient/index',    title: 'Twitter Client',        type: 'detailed',   nav: 1}
    ])
    .buildNavigationModel();

return {
    router: childRouter,
    introSamples: ko.computed(function() {
        return ko.utils.arrayFilter(childRouter.navigationModel(), function(route) {
            return route.type == 'intro';
        });
    }),
    detailedSamples: ko.computed(function() {
        return ko.utils.arrayFilter(childRouter.navigationModel(), function(route) {
            return route.type == 'detailed';
        });
    })
};

});

于 2013-09-01T14:37:02.107 に答える