2016-10-18 3 views
0

4 개 라인을 정의 템플릿을 찾을 수없는이 코드 :유성 나중에

//hello.js 

import { Meteor } from 'meteor/meteor'; 
import { Template } from 'meteor/templating'; 

import './hello.html'; 

Template.hello.onCreated(function helloOnCreated() { 
// counter starts at 0 
this.counter = new ReactiveVar(0); 
}); 

Template.hello.helpers({ 
counter() { 
    return Template.instance().counter.get(); 
}, 
}); 

Template.hello.events({ 
'click button'(event, instance) { 
    // increment the counter when button is clicked 
    instance.counter.set(instance.counter.get() + 1); 
}, 
}); 

<!-- hello.html --> 

<body> 
    <h1>Welcome to Meteor!</h1> 

    {{> hello}} 
    {{> info}} 
</body> 

<template name="hello"> 
    <button>Click Me</button> 
    <p>You've pressed the button {{counter}} times.</p> 
</template> 

<template name="info"> 
    <h2>Learn Meteor!</h2> 
    <ul> 
    <li><a href="https://www.meteor.com/try" target="_blank">Do the Tutorial</a></li> 
    <li><a href="http://guide.meteor.com" target="_blank">Follow the Guide</a></li> 
    <li><a href="https://docs.meteor.com" target="_blank">Read the Docs</a></li> 
    <li><a href="https://forums.meteor.com" target="_blank">Discussions</a></li> 
    </ul> 
</template> 

반환이 오류 :

Error: No such template: hello 
    at lookup.js:189 
    at Blaze.View.<anonymous> (spacebars-runtime.js:32) 
    at view.js:199 
    at Function.Template._withTemplateInstanceFunc (template.js:465) 
    at view.js:197 
    at Object.Blaze._withCurrentView (view.js:538) 
    at viewAutorun (view.js:196) 
    at Tracker.Computation._compute (tracker.js:311) 
    at new Tracker.Computation (tracker.js:201) 
    at Object.Tracker.autorun (tracker.js:576) 

가 터무니없이 긴 얻기 위해이를 방지하기 위해, 필요한 경우 여기 GitHub repo입니다.

tutorial에서 서식 파일은 호출 후에옵니다. 그러나 웬일인지, 그것은 나의 페이지 위에 없을 것이다. 템플릿을 통화 위에 놓으면 작동하지만 이후에는 작동하지 않습니다. 내가 뭘 잘못하고 있는지 모르겠다.

다음은 요청 된 디렉토리 구조입니다. 나는 방금이 프로젝트를 시작했고, 안녕하세요.

directory[2]

+0

디렉토리 구조를 확인해야 할 수도 있습니다. Meteor에는 클라이언트 측 가져 오기 순서에 대한 몇 가지 규칙이 있습니다. – ilrein

+0

@ilrein 디렉토리 구조를 추가했습니다. 더 많은 정보가 필요하시면 알려주십시오. – amflare

답변

0

또한 단지 작업 디렉토리를 나타내는 각 파일의 상단에 코멘트를 추가해야합니다.

코드의 첫 번째 조각은 hello.js의 내용이고 두 번째 조각은 main.html의 내용으로 가정합니다. 나는 또한 당신이 우리에게 hello.html의 내용을 보여주지 않는다고 가정합니다.

모든 해당하는 경우, 당신이 hello.jshello.html를 가져하지만 당신은 또한 main.html 이내에 hello.html를 참조하는 것을 볼 수 있습니다. 나는 당신의 실수가 올바른 기준이 무엇인지 혼란스럽고 잘못된 것을 잡는 것이라고 생각합니다.

깨끗한 코드는 Meteor 템플릿을 자신의 디렉토리와 파일로 분리하는 경향이 있습니다. 나는 main.html에서 그것들을 제거 할 것이다.

UPDATE :

나는 당신의 문제가 아니라 당신의 main.js에서, 또는 생각, 라우팅 파일.

처음에는 코드 중간에서 가져 오는 것이 좋지 않습니다. 좋은 연습은 다음과 같습니다

1) 가져 오기 모든 절대 경로 2) 간격 3) 모든 상대 경로 4 가져 오기) 그

당신이에 추가 한 BlazeLayout.render @ 좋은 모습을 찍은 후 가져 절대로 추가하여 프로젝트이지만 사용하지는 않았습니다. JS 파일을 뻔뻔스럽게 가져 오려고하면 절대로 작동하지 않습니다. 렌더하려는 템플릿이 포함 된 render 메소드에 인수를 전달해야합니다.

+0

둘 다 hello.html/js입니다. 혼란에 사과드립니다. 이것이 당신의 대답을 전혀 바꾸지 않습니까? 내 main.js도 볼 필요가 있습니까? – amflare

+0

main.html/main.js를 볼 수 있습니다. – ilrein

+0

여기 있습니다. https://github.com/tbirrell/chess-meteor/blob/master/client/main.js https://github.com/tbirrell/chess-meteor/blob/master/client/main.html – amflare