2

dojoでテンプレートを作成するとこんな感じ。

<div id="test" data-dojo-type="dojox.mobile.View" class="test">
     <h1>TESTER</h1>
</div>

いくつかの dojo ライブラリをインポートし、dojo ドキュメントのコードに従います。

require(["dojo/router"], function(router){
  router.register("test/:id", function(evt){
    // Will fire when the hash matches
    // evt.params.id will contain what is passed in :id
  });

  // Startup must be called in order to "activate" the router
  router.startup();
});

URL の ':id' の値の取得は完了しましたが、ブラウザ コンソールにエラーが表示されます。

Uncaught TypeError: Cannot call method 'isVisible' of undefined

これは、場所のハッシュに対して呼び出されてトリガーされるテンプレートがなく、動的 URL が必要なため、テンプレートの ID ( id='test' と 'test/:id' ) が同じでないためです。

前もって感謝します、神のご加護を.. ^_^

4

1 に答える 1

0

これは私がそれを行う方法の単なる例であり、非常に簡単です

require(["dojo/router", "dojo/dom"], function(router, dom){
    //Have a config, matching id/widget
    var pages = {
        "id1": "some/widget1",
        "id2": "some/widget2",
    }
    router.register("test/:id", function(evt){
        //require the widget and place it in some div
        require([pages[evt.params.id], function(Page){
            (new Page()).placeAt(dom.byId('somDiv'));
        });
    });


    router.startup();
});
于 2016-01-05T21:58:32.567 に答える