문자열을 사용하고 컬렉션에서 문서를 찾음에 따라 세션을 설정하는 함수가 있습니다. 이 특별한 경우에는 문자열이 게임 name
의 가능한 이름이고 세션을 해당 게임에 설정합니다. _id
URL Meteor.startup 내에서 구문 분석이 작동하지 않습니다.
문제는 템플릿 이벤트에 바인딩 할 때 예상대로 작동하지만 Meteor.startup
에 함수를 호출하면 전혀 작동하지 않습니다. 참고로 - 현재로서는 자동 게시를 실행 중입니다. (나는이 단계 이후에 발행/구독 설정을 조정할 계획.) 이것은 문자열을 받아 적절하게 세션을 설정하는 기능입니다
: 나는에이 기능을 사용하는 홈 페이지에서
var enterExisting = function(n) {
var g = Games.findOne({name:n});
var e = "That game doesn't exist.";
Session.set("error", null);
Session.set("no_game", null);
if (Validation.game_exists(n)){
Validation.clear();
Session.set("current_game", g._id);
window.location.hash = ("/" + n);
} else {
Session.set("error", e)
}
};
을 양식 및 예상대로 작동합니다. 세션을 설정하고 게임을 표시하며 URL을 변경합니다. 이것은 해당 양식에 사용되는 방법입니다
Template.entergame.events({
'click input.enter-game': function(){
var n = document.getElementById('enter-game-name').value;
enterExisting(n);
}
});
나는 그것이 세션을 설정하거나 나에게 지시하지 않는 Meteor.startup
에 유사한 방법으로 같은 기능을 사용하려고하면.
Meteor.startup(function() {
Session.set("current_game", "");
Session.set("error", null);
Session.set("no_game", null);
var n = location.hash.substring(2);
if (n.length === 0) {
window.location.hash = "#/"
} else {
enterExisting(n);
}
});
나는 관련이있을 것으로 예상하지만, 단지의 경우 여기에 "게임에 참여"형태의 템플릿입니다하지 않습니다 당신이 'Meteor를 교체 할 경우
<template name="entergame">
<div class="enter-game">
{{#if error}}
<p class="error bad-entry">
{{error}}
</p>
{{/if}}
<input id="enter-game-name" type="text" placeholder="Join an Existing Game!" />
<input type="button" class="enter-game" value="»">
</div>
</template>
이것이 작동하지 않는 이유는 확실하지 않지만 권장 사항 : 1) http://docs.meteor.com/#session_set_default를 사용하고 2) https://github.com/tmeasday/meteor-router 또는 최신 https://github.com/EventedMind/iron-router로 클라이언트 측 라우팅을 수행하십시오. – emgee