2014-11-17 46 views
0

,我有以下的迪朗達爾設置導航:迪朗達爾導航:ATTR HREF約束力不工作

layout.js

... 
that.activate = function() { 
    router.map([ 
     { route: '', title: abp.localization.localize('HomePage', 'MyProject'), moduleId: 'viewmodels/home', nav: true, menuName: 'Home' }, 
     { route: 'editpage/:id', title: abp.localization.localize('EditPage', 'MyProject'), moduleId: 'viewmodels/editpage', hash: '#/editpage/id' } 
    ]).buildNavigationModel(); 

pages.js

... 
that.editPage = function (page) { 
    that.router.navigate('editpage/' + page.id()); 
}; 

pages.cshtml

<ul class="list-group" data-bind="foreach: pages"> 
    <div class="list-group-item"> 
     <span class="page-name" data-bind="text: name"></span> 
     <div class="text-right"> 
      <!--<button type="button" class="btn btn-info btn-sm" data-bind="click: $parent.editPage">--> 
      <button type="button" class="btn btn-info btn-sm" data-bind="attr: {href: '#/editpage/' + id()}"> 
       <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> @L("EditPage") 
      </button> 
     </div> 
    </div> 
</ul> 

當我點擊Edit Page按鈕時,我想導航到「EditPage /:id」頁面。然而,只有點擊綁定的工作:

<button type="button" class="btn btn-info btn-sm" data-bind="click: $parent.editPage"> 

的Attr HREF綁定不:

<button type="button" class="btn btn-info btn-sm" data-bind="attr: {href: '#/editpage/' + id()}"> 

我嘗試配置的幾種方法,但他們都不似乎幫助。我猜它只是在路由配置或散列中的一個不正確的語法。無法弄清楚。

任何幫助,將不勝感激!

回答

0

我以前沒有使用過散列參數。但是,根據路由器文檔(http://durandaljs.com/documentation/Using-The-Router.html),您要查找的散列字面上是#/editpage/id,您傳遞的散列是'#/editpage/' + id()。試着寫出下列代替:

路由器:

{ route: 'editpage/:id', title: abp.localization.localize('EditPage', 'MyProject'), moduleId: 'viewmodels/editpage', hash: '#editpage/:id' } 

<button type="button" class="btn btn-info btn-sm" data-bind="attr: {href: '#editpage/' + id()}"> 

此外,如果你只是超鏈接到的路線(如您已完成),並從路徑刪除哈希參數,你應該沒問題。