流星來自測試版,我非常興奮使用它。我將它安裝在我的Windows機器上(從http://win.meteor.com/)並創建了一個應用程序。下面的代碼:無法讀取未定義的屬性'助手'
HTML:
<!-- simple-todos.html -->
<head>
<title>Todo List</title>
</head>
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
的javascript:
// simple-todos.js
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: [
{ text: "This is task 1" },
{ text: "This is task 2" },
{ text: "This is task 3" }
]
});
}
這是完全相同的代碼作爲official meteor tutorial。如果我運行該示例,則標題呈現得很好。另一方面,該列表完全沒有出現。不知何故,幫手不工作。我收到以下javascript錯誤:
Uncaught TypeError: Cannot read property 'helpers' of undefined
在流星控制檯中,沒有打印錯誤或警告。我對流星非常興奮,我很樂意將它用於生產應用程序,所以請幫助我解決這個問題(可能非常簡單)。我希望這不僅是Windows中的一個問題(流星尚未正式發佈的Windows)。
我首先要做的是加上'console.dir(模板) ;'嘗試調用'.helpers()'之前。問題在於'.body'是'undefined',因此找出'Template'的外觀是很有用的。 – Pointy 2014-11-08 16:11:22