당신은 (내가 원시 HTML로 예를 사용하는거야하지만 당신은 대신에 표시하는 것을 내용으로 자신의 기능을 구현하는 더 나을 수도 콜렉션의 데이터를 사용하여 반응성 사업부를 사용하여 더 좋을 수 있습니다
를 즉
는 기본적으로 핫 코드 스왑
클라이언트 측 HTML 코드
<template name="home">
<div>
{{{content}}}
</div>
</template>
JS를 통해 reactivity을 활용 코드
if(Meteor.isClient) {
MyCollection = new Meteor.Collection("MyCollection")
Template.home.content = function() {
if(MyCollection.findOne()) {
return MyCollection.findOne().content
}
}
}
if(Meteor.isServer) {
MyCollection = new Meteor.Collection("MyCollection")
//Set an initial content if there is nothing in the database
Meteor.startup(function() {
if(!MyCollection.findOne()) {
MyCollection.insert({content:"<h1>Test content</h1><p>Test Data</p>"
}
}
//A method to update the content when you want to
Meteor.methods({
'updatecontent':function(newcontent) {
id = MyCollection.findOne()._id
MyCollection.update(id, {$set:{content:newcontent}});
return "Done"
}
}
당신은 어느 몽고 수집 또는 (웹 콘솔, 클라이언트 측 또는 서버 측 자바 스크립트) 같은 것을 사용하여 컨텐츠를 업데이트 할 수 있습니다
는 :
Meteor.call("updatecontent","New content",function(err,result) {
if(!err) {
console.log(result)
}
});
코드가 실시간으로 업데이트됩니다 어떤 당신이 그것을 사용할 때.
나는 꽤 오래입니다하지만 그것의 대부분은 HTML/업데이트 설정되어 죄송합니다. 실제로 사용자의 페이지를 새로 고침하는 핫 코드 스왑보다 훨씬 좋음