2014-10-10 2 views
-1

페이지 렌더링이 철자와 작동하지 않습니다. 라우터가 도와줍니다. 렌더링이 코드와 작동하지 않습니다. 아래 코드를 찾으십시오. 우리는 유성 추가 : 라우터 0.9.4입니다. 사용 된 유성 0.9.3.1. 페이지 렌더링이 무뚝뚝해서 죄송유성의 동적 페이지 렌더링

Router.route("/", function() { 
    this.render("route"); 
}); 

답변

0

을 router.js

<head> 
</head> 
<body > 
    <div> 
     {{> players}} 
    </div> 
</body> 

<template name ="editform"> 
    <div class="container"> 
    <div class="row" style="border-bottom: 5px solid gray;"> 
     <h2>Profile</h2> 
    </div> 
    <div id="wrapper"> 
     <table> 
      <tr> 
       <td>First name:</td> 
       <td><input type="text" name="pff_name"/></td> 
      </tr> 
      <tr> 
       <td>Last name:</td> 
       <td><input type="text" name="pfl_name"/></td> 
      </tr> 
      <tr> 
       <td>Email Address:</td> 
       <td><input type="email" name="pfemail"/></td> 
      </tr> 
      <tr> 
       <td>Phone number:</td> 
       <td><input type="text" name="pfname"/></td> 
      </tr> 
      <tr> 
       <td>Company or Organization:</td> 
       <td><input type="url" name="pfname"/></td> 
      </tr> 
     </table>   
    </div> 
    </div> 
</template> 

<template name="players"> 
    <div> 
     <table class="table table-condensed table-striped table-bordered table-hover no-margin"> 
      <tr> 
       <th>IP</th>    
       <th></th> 
      </tr> 
      {{#each scorers}} 
      <tr> 
       <td><a href="{{ pathFor 'editform' }}" >{{ ip }}</a></td>    
       <td></td> 
      </tr> 
      {{/each}} 
     </table> 
    </div> 
</template> 

작동하지 않습니다,하지만 당신은 정말 this를 읽을 필요가있다. 아주, 아주 그것이 말하는 상단에

:

Router.route('/', function() { 
    this.render('Home'); 
}); 

사용자가 URL "/"로 이동

는 경로는 위의 페이지에 "홈"라는 이름의 템플릿을 렌더링합니다.

라우터에는 this.render("route"); 행이 있지만 "route"라는 템플릿은 없습니다.

+0

죄송합니다. 죄송합니다. 이. 렌더링 ("편집 폼"). 도와주세요. 미리 감사드립니다. – user2740350

+0

죄송합니다. 이것이 이상적인 것입니다. 이. 렌더링 ("편집 폼"). 도와주세요. 미리 감사드립니다. @ richsilv – user2740350

1

달성하려는 목표가 명확하지 않습니다.
먼저 Meteor Docs을 먼저 읽어 보시기 바랍니다.
/클라이언트 (클라이언트 측 코드 파일)
/서버 (서버 측 코드 파일)
collections.js
Check out a good way of structuring your app here.

:이 같은 구조를 사용할 수있는이 같은 간단한 앱

먼저 여기에 <head><body> 태그가 필요하지 않습니다.
그런 다음 플레이어 템플릿을 렌더링하도록 설정하고 머리글, 바닥 글 등을 페이지에 추가 할 수있는 클라이언트 폴더에 레이아웃 템플릿을 만들 수 있습니다.

<template name="layout"> 
    {{>players}} 
</template> 




layout.html 그런 다음 당신은뿐만 아니라 클라이언트 폴더에 플레이어 템플릿이 필요합니다. 나는 앞으로 나아갈 수있는 간단한 예제를 만들어 볼 것입니다. 사용자 입력 값이 수집되어 플레이어 컬렉션에 삽입되고 해당 컬렉션의 각 플레이어에 대해 {{players}} 헬퍼를 사용하여 div.result에 새 테이블 행이 생성됩니다.

players.html

<template name="players"> 
    <div class="container"> 
     <div class="row" style="border-bottom: 5px solid gray;"> 
      <h2>Profile</h2> 
     </div> 
     <div id="wrapper"> 
      <table> 
       <tr> 
        <td>First name:</td> 
        <td><input type="text" id="pff_name" /></td> 
       </tr> 
       <tr> 
        <td>Last name:</td> 
        <td><input type="text" id="pfl_name" /></td> 
       </tr> 
      </table> 
      <button class="insert">Submit</button> 
     </div><br/> 
     <div id="result"> 
      <table class="table table-condensed table-striped table-bordered table-hover no-margin"> 
      <tr> 
       <th>First Name</th> 
       <th>Last Name</th> 
      </tr> 
      {{#each players}} 
      <tr> 
       <td>{{firstname}}</td> 
       <td>{{lastname}}</td> 
      </tr> 
      {{/each}} 
      </table> 
     </div> 
    </div> 
</template> 



collections.js
새로운 유성 컬렉션 만들기
모든 추가 문서를 저장할하는 플레이어를했다.

Players = new Meteor.Collection("players"); 


선수.JS 여기
선수 도우미는 커서라고 addPlayer라는 이름의 생성 유성 방법을 반환합니다.

Template.players.helpers({ 
    players: function() { 
     return Players.find(); 
    } 
}); 

Template.players.events({ 
    'click .insert': function(event, template) { 
     var first = $('#pff_name').val(); 
     var last = $('#pfl_name').val(); 
     if(first !== "" && last !== "") { 
      Meteor.call("addPlayer", first, last); 
     } 
     $('#pff_name').val(""); 
     $('#pfl_name').val(""); 
    } 
}); 


server.js

Meteor.startup(function() { 
    Meteor.methods({ 
     addPlayer: function(fname, lname) { 
      Players.insert({firstname: fname, lastname: lname}); 
     } 
    }) 
}); 


routrer.js 플레이어 컬렉션에 플레이어를 추가
플레이어 템플릿을 렌더링하기 위해 철 라우터에게

Router.map(function() { 
    this.route('players', { 
     path: '/', 
     template: 'players', 
     layoutTemplate: 'layout' 
    }) 
}); 



편집 : 당신은 당신의 경로는 새 버전에 대해 정의 된
IronRouter 버전 0.9.4, 을 사용하지만 있습니다.
IronRouter를 iron : [email protected]또는으로 업데이트하십시오.이 버전에 대해 부여한 표기법을 따르십시오.

+0

응답 해 주셔서 감사합니다. 실제로 유성에서 페이지 렌더링이 필요합니다. @ durrrr – user2740350

+0

나는 팔로우하지 않습니다. 이것은 유성입니다. @ user2740350 – durrrr