未啓動流星方法回調我正在使用Meteor。正如你可以在Github上的ValidatedMethod的README中看到的,它在調用一個方法時使用了returnStubValue選項,但它似乎不適用於我。我想知道你對此有何看法。客戶端模擬後使用ValidatedMethod
我已經上傳了重現Github上該問題的簡單流星項目:Link to the repository
這裏是我的服務器端方法:
export const createTodo = new ValidatedMethod({
name: 'todos.create',
validate: new SimpleSchema({
todo: String,
}).validator(),
run({ todo }) {
if (this.isSimulation) {
return { finished: false };
}
Todos.insert({ todo });
return { finished: true };
},
});
這是在插入待完成的簡單方法託託斯收藏。在客戶端,我立即返回一個對象{ finished: false }
。在服務器端更新我的數據庫,然後返回一個對象{ finished: true }
這裏是我的客戶端的方法調用:
createTodo.call({ todo }, (err, res) => {
console.log(res);
});
我只是調用的方法和CONSOLE.LOG結果。 因爲我使用mdg:驗證方法,它使用returnStubValue
選項,我猜我的控制檯應該輸出finished: false
,然後finished: true
。但它實際上只輸出finished: true
。
有什麼我不明白的嗎?
你想完成什麼?檢查'this.isSimulation'是否是沒有意義的,因爲你的方法的全部_is_模擬。 –
我想指出何時寫入服務器正在進行中,使用與Meteor指南中所示完全相同的方式:[just here](https://guide.meteor.com/ui-ux.html#writes-進行中)。 我的方法體是運行服務器和客戶端,實現[樂觀用戶界面](https://guide.meteor.com/ui-ux。html#optimistic-ui) –