jQuery and Meteor반응 환경에서 jQuery를 트리거하는 방법은 무엇입니까?
Meteor는 초기 페이지로드가있는 Web Apps의 세계에서 탄생했습니다. jQuery는 서버 생성 페이지의 세계에서 태어났습니다.
그래서, 질문은 ... 언제 유성 템플렛에서 jQuery 플러그인을 호출할까요?
1) 페이지로드시 -> 작동하지 않습니다. 데이터가 아직 없습니다.
Template.contextualFeed.feedItems = ->
Feed.find()
$("abbr.timeago").timeago() # Calling the feed right away is useless as Feed.find() is initially empty and will populate a bit later when subscription is delivering the initial data.
<template name="contextualFeed">
<ul class="feed {{isActive "feed"}}">
{{#each feedItems}}
<li class="popup-holder">
{{> contextualFeedItem}}
</li>
{{/each}}
</ul>
</template>
각 항목 -> 작품에 2),하지만 매우 낭비 보인다. 모든 항목이로드되면 후
Template.contextualFeed.feedItems = ->
Feed.find()
Template.contextualFeed.jQueryMe = ->
$("abbr.timeago").timeago() # Works, but seems incredibly wasteful
<template name="contextualFeed">
<ul class="feed {{isActive "feed"}}">
{{#each feedItems}}
<li class="popup-holder">
{{> contextualFeedItem}}
{{jQueryMe}}
</li>
{{/each}}
</ul>
</template>
3) -> 작품,하지만 여전히 그것이 있어야로 우아하지 않다 ...
Template.contextualFeed.feedItems = ->
Feed.find()
Template.contextualFeed.jQueryMe = ->
Meteor.defer ->
#(cut) some ugly code to make sure it only executes once.
$("abbr.timeago").timeago() # Works, but seems incredibly wasteful
<template name="contextualFeed">
<ul class="feed {{isActive "feed"}}">
{{#each feedItems}}
<li class="popup-holder">
{{> contextualFeedItem}}
{{jQueryMe}}
</li>
{{/each}}
</ul>
</template>
4) 그럴까가 어떤 이벤트가 화재 때 데이터가 모든 항목에 별도로 추가되지 않고로드됩니까?
그래서 유성 템플레이트에서 jQuery를보다 깨끗하게 호출 할 수 있습니까?
PS : 코드 예제는 커피 스크립트에 ... 그것을에도 불구하고 좋은 수)
안녕하세요 theresaanna, 음, 나는 "2 시간 전"으로 날짜/타임 스탬프를 변환하는 jQuery 플러그인을 사용하려고합니다. 예제 2에서 jQuery 초기화 코드는 기본적으로 루프 내에서 호출되며, 피드 항목 당 한 번 지나치게 과장되어 보인다. – thomasf1
답장을 보내 주셔서 감사합니다 ... 구독을 위해 콜백을 추가하고 생각하고 있어요. 내가 시도 해봐야 할 일 ... 이전 프레임 워크에서 내가 사용한 것은 단순히 이벤트를 Collection에 바인딩하여로드되었을 때 앱의 다른 부분에 알릴 수 있었다는 것입니다. 근원에서 저것 같이 무언가를 찾아 낼 것이다 ... – thomasf1