클라이언트의 모음에 자동 가입하고 있습니다. 내 코드는 아래와 같습니다. 나는 클라이언트가 업데이트 된 정보를 가지길 기대하지만 결코 업데이트하지 않는다. 이 문제는 페이지를 새로 고치지 않으면 메시지로 대체되지 않는 단추에 나타납니다.테스트 컬렉션이 업데이트되지 않는 이유는 무엇입니까?
'Tests'컬렉션에 대한 하나의 문서는 클라이언트의 testCount 속성을 1로 업데이트해야하지만, 페이지를 새로 고침하지 않으면 절대로 발생하지 않습니다. 업데이트하지 않겠습니까?
자동 게시 패키지가 설치되어 있지 않습니다.
이 시점에서 나는 Meteor에 버그가 있다는 것을 확신합니다. 또는 나는 단지 근본적인 것을 이해하지 못합니다. Meteor.js의 dev 버전을 설치하려고합니다. Meteor.js가 실제로 작동 할 때까지 그냥 포기해야합니다. : P
내 콘솔 로그 :
Tests updated!
checking test
no test
Tests updated! Object {_id: "ea9f6002-74c7-4f37-9f10-0167b3b6f65a", testCount: 0}
checking test result
test.testCount 0
내 서버 로그 :
$ meteor reset;meteor
Project reset.
[[[[[ ~/Dropbox/projects/sphela-game/sphela ]]]]]
Running on: http://localhost:3000/
inserting new test
Connecting test, getting initial data.
Test added do nothing { testCount: 0, _id: 'ea9f6002-74c7-4f37-9f10-0167b3b6f65a' }
Connecting test, getting initial data.
Test added do nothing { testCount: 0, _id: 'ea9f6002-74c7-4f37-9f10-0167b3b6f65a' }
Running test.
Updating test to 1.
Test ran. { testCount: 1, _id: 'ea9f6002-74c7-4f37-9f10-0167b3b6f65a' }
Test added do nothing { testCount: 1, _id: 'ea9f6002-74c7-4f37-9f10-0167b3b6f65a' }
내 HTML :
<head> <title>Testing counts.</title> </head>
<body> {{> app}} </body>
<template name="app">
{{#if testSuccess}}
<h1>Test complete.</h1>
{{else}}
<button class="btn run-test">Run Test</button>
{{/if}}
</template>
내 자바 스크립트 :
var Tests = new Meteor.Collection('tests');
if (Meteor.isClient) {
Meteor.startup(function() {
Session.set('testCount', 0)
Meteor.subscribe('connect');
});
Template.app.testSuccess = function() {
var test;
console.log('checking test result');
test = Tests.findOne();
if (!test) {
console.log('no test', test);
return false;
}
console.log('test.testCount', test.testCount);
return test.testCount > 0;
};
Template.app.events({
'click .run-test': runTest
});
function runTest(event) {
Meteor.call('runTest');
Session.set('testCount', 1);
}
Meteor.autorun(function() {
console.log('Tests updated!', Tests.findOne());
});
Meteor.autosubscribe(function() {
Meteor.subscribe('test-results', Session.get('testCount'));
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
test = Tests.findOne({})
if (!test) {
test = {
testCount: 0
};
console.log('inserting new test');
test._id = Tests.insert(test);
} else {
console.log('startup reset');
test.testCount = 0;
Tests.update({_id:test._id}, test);
}
});
Meteor.publish('connect', function() {
var test_;
console.log('Connecting test, getting initial data.');
test_ = Tests.findOne({});
this.set('tests', test_._id, test_);
this.complete();
this.flush();
});
Meteor.publish('test-results', function(test) {
var handle;
handle = Tests.find({testCount: test}).observe({
changed: _.bind(function(test) {
console.log('Test changed', test._id, test.testCount);
this.set('tests', test._id, test);
this.flush();
}, this),
added: _.bind(function(test) {
console.log('Test added do nothing', test);
this.flush();
}, this)
});
this.complete();
this.flush();
this.onStop(function() {
handle.stop();
});
});
Meteor.methods({
runTest: function() {
var test;
console.log('Running test.');
test = Tests.findOne({});
test.testCount = 1;
console.log('Updating test to 1.');
Tests.update({_id: test._id}, test);
console.log('Test ran.', Tests.findOne());
},
});
}
당신이 autopublish 패키지 설치가 있었나요? –
완전히 잊어 버렸습니다. 제거한 후에도 나는 당신과 같은 경험을합니다. –
그럼 버그인가요? –