2014-02-25 3 views
0

유성과 함께 블로그 작업을하고 있는데 검색 부분에 도달했습니다. 이제 검색 조건에 따라 템플릿 변수로 이동하는 데이터를 변경하고 싶습니다. 현재로서는 템플릿에서 렌더링 할 데이터를 다시 정렬하는 방법을 이해하지 못합니다. HTMLMeteor 템플릿 쿼리 변경, 데이터베이스에서 콘텐츠를 변경하는 방법?

<template name="posts"> 
    {{#each post}} 
    <div class = "postWrapper"> 
    <p>{{postTitle}} - <small><em>{{userName}}<em></small></p> 
    <p><small>{{postDate}}</small><p> 
    <div class="postText">{{safe 'postText'}}</div> 
    <br/> 
    </div> 
    {{/each}} 
</template> 

자바 스크립트

Template.posts.post = function(){ 
    return TestPosts.find({}, {sort: {timeStamp: -1}, limit: 100}); 
} 

그것을 다른 뭔가를해야만으로 정렬되도록 나는 Template.posts.post 쿼리를 어떻게 변경합니까 : 여기

내가 지금 가지고있는 것입니다 타임 스탬프보다. Template.posts.post 쿼리를 변경하면 이벤트가 시작될 때 아무 것도 나타나지 않습니다.

Template.searchForm.events = { 
    "click .cancelBtn": function(){ 
     $("#lightbox-container, #searchForm, #postForm").hide(); 
    }, 
    "click #searchBtn": function(){ 
     var reply = TestPosts.find({}, {sort: {timeStamp: 1}}); 
      //what do I need here to be able to change the posts returned 
      //to the template? 
    } 
    } 

meteor.render를 사용하려고했지만 아무 것도하지 않았습니다. 어떤 지침이 좋을 것입니다.

답변

1

당신은 절차 적으로보다는 "반응 적"으로 생각하기를 원할 것입니다. 도움이된다면, 반응 적 사고는 선언적 사고와 약간 비슷합니다. 단지보고 싶은 것을 선포하고 Meteor가 방법과시기를 파악하도록하십시오. 그걸 염두에두고

,이 (정렬 순서를 세션 변수를 만들기) 당신을 위해 일 수 있습니다

내가 이런 식으로 생각하지 않았다
Session.setDefault('sortOrder', {'timestamp': -1}); 
Template.posts.post = function(){ 
    return TestPosts.find({}, {sort: Session.get('sortOrder'), limit: 100}); 
} 

Template.searchForm.events = { 
    "click .cancelBtn": function(){ 
    $("#lightbox-container, #searchForm, #postForm").hide(); 
    }, 
    "click #searchBtn": function(){ 
     Session.set('sortOrder', {'timestamp': 1}); 
    } 
} 
+0

는,이 많이 변경합니다. 시간 내 주셔서 감사합니다. –

관련 문제