2017-04-01 15 views
-1

Durandal, RequireJS, KnockoutJS녹아웃 대체보기

나는 일반적이고 내 프로젝트의 클라이언트 특정 볼 수 있습니다.

│ faq.html 
│ welcome.html 
│ shell.html 
│ 
├───Client1 
│  faq.html 
│ 
├───Client2 
│  faq.html 
│  welcome.html 

클라이언트 특정보기가있는 경우 표시하거나 그렇지 않으면 기본보기를 표시하려고합니다.

이와 비슷한 것.

<div> 
    <div data-bind="compose: { view:'views/Client1/faq.html', fallbackView: 'view/faq.html' }"></div> 
</div> 

답변

0

나는보기보다는보기 모델에서 이것을 처리하는 것이 좋습니다. Durandal는이 같은 것을 할 수 있도록 바인딩의 작성에 대한 관찰 속성을 사용할 수 있습니다 :보기 경로를로드 할

viewModel = function(){ 
    var self = this; 
    self.currentView = ko.observable(); 

    self.loadView = require(['text!views/Client1/faq.html', 'text!view/faq.html'], function(clientView, defaultView) { 
     if(clientView) { 
      self.currentView('views/Client1/faq.html'); 
     } else { 
      self.currentView('view/faq.html'); 
     } 
    }); 

} 

두 배 물론 약간 중복 보인다 ...

<div> 
    <div data-bind="compose: { view: currentView }"></div> 
</div> 

을하지만, 보기가 존재하는지 여부를 알 수있는 다른 방법이 없으면 최선의 방법이 될 수 있습니다.