在模板助手中記錄資料上下文的資訊
以下內容使用 Chrome Logging API。如果在多個模板中使用 .group()
語法,它將以圖形方式將來自不同模板的控制檯日誌組織到分層樹中。
你還可以瞭解如何檢查當前資料上下文以及如何對資料進行字串化。
Template.landingPage.getId = function(){
// using a group block to illustrate function scoping
console.group('coolFunction');
// inspect the current data object that landingPage is using
console.log(this);
// inspect a specific field of the locally scoped data object
console.log(JSON.stringify(this._id);
// close the function scope
console.groupEnd();
return this._id;
}