2014-03-31 41 views
2

使用autoform和依賴關係加上鐵路路由器。 Autopublish已打開,我正在客戶端控制檯上看到該集合。 .8上的新項目,全新安裝。使用Autoform時出現Meteor Scope錯誤

在schema.js,我已經嘗試在幾個位置(/ lib下,/)

Tvseries = new Meteor.Collection("tvseries", { 
schema: { 
    title: { 
     type: String, 
     label: "Title", 
     max: 250 
    }, 
    airStartDate: { 
     type: Date, 
     label: "First episode air date" 
    } 
} 

});

然後從例如採取了非常基本的自動窗體:

<template name="addseries"> 
    {{> quickForm collection="tvseries" id="inserttvseriesForm" type="insert"}} 
</template> 

另外一個途徑就是剛裝這種形式:

Router.map(function() { 
    this.route('addseries', { 
    path: '/addseries', 
    template: "addseries" 

    }); 
}); 

我得到的JS控制檯此消息:

Exception from Deps recompute function: Error: tvseries is not in the window scope. 

回答

2

你有一個錯字:

<template name="addseries"> 
    {{> quickForm collection="Tvseries" id="inserttvseriesForm" type="insert"}} 
</template> 

您的收藏被命名爲Tvseries,而不是tvseries

1

如果塞爾坎的錯字建議沒有工作,和任何人,因爲這尋找減免這顯示在谷歌,是我是怎麼來的:

docs(這部分是埋太遠國際海事組織)

schemacollection的值應該在它周圍加引號嗎?

如果您使用引號,那麼您正在告訴autoform「在窗口範圍內使用該名稱查找對象」。所以如果你在你的客戶端文件的頂層定義你的集合,並且沒有var關鍵字,那麼你可以使用這個技巧來避免編寫幫助者。

如果您不使用引號,那麼您必須使用該名稱定義一個輔助函數,並讓它返回SimpleSchema或Mongo.Collection實例。

所以你需要一個輔助函數,應該是這樣的:

Template.addseries.helpers({ 
    Tvseries: function() { 
    Return Tvseries; 
    } 
}); 

如果你有沒有被安裝在採取一個模式,你還需要創建另一個助手返回該模式,以便您可以從模板中調用它。文檔建議全球註冊此幫助者:

Template.registerHelper('Schemas', Schemas); 
相關問題