2013-01-04 2 views
10
function UsersVM(start_page){ 
    var self = this; 
    console.log('start form ' + start_page); 
    self.go_to = function(page) { 
    location.hash = '#Users/' + pageNumber;  
    } 
} 

Sammy(function() { 
    this.get('/app/?#Users/:page', function() { 
     var vm = new UsersVM(this.params.page); 
     ko.applyBinding(vm);    
    }); 
}).run(); 

를 트리거하지 않고 나는 다음과 같은 코드를 사용하여 페이지의 해시를 변경하고 싶습니다. 백본에서 다음과 같이 할 수 있습니다.변경 해시 새미 이벤트를

app.navigate("help/troubleshooting", {trigger: false}); 

Sammy에서 할 수 있습니까? 감사합니다.

+0

나는 또한 어떻게하는지 알아 내려고 노력하고 있습니다. 해결책을 찾았습니다. @Andrew Luzkovky? – punkbit

답변

0

사용하여 다음과 같은 코드 : 그런 다음

var sam = $.sammy(function() { 
    var sammy = this; //get a persistent reference to this 

    sammy.quiet = false; //set quiet to false by default 

    //I set quiet to true before running a route 
    sammy.quietRoute = function (location) { 
     sammy.quiet = true; 
     sammy.setLocation(location); 
    } 

    //I'm called after every route to reset quiet to false 
    sammy.after(function() { 
     sammy.quiet = false; 
    }); 

    //I'm a 'normal' route that does not have the capability to be 'quiet' 
    this.get('#normalRoute', function() { 
     //routing code 
    }); 

    //I am a route that can be 'quieted' so that when the url or 
    //hash changes my routing code doesn't run 
    this.get('#quietableRoute', function() { 
     if (!sammy.quiet) { 
      //routing code 
     } else { 
      return; 
     } 
    }); 

}); 

: 여기 새미에서이 작업을 수행 할 수있는 기본 방법을 알고 있지만하지 않는

var new_location = '#foo'; 
app.trigger('redirect', {to: new_location}); 
app.last_location = ['get', new_location]; 
app.setLocation(new_location); 
5

나를 위해 일했다 솔루션입니다 코드의 quietRoute 함수를 호출하십시오.

관련 문제