我有關於關係和autoform的collection2的問題。 我嘗試實現1:n關係,其中每個對象都有一個objectType,而每個objectType可以引用多個對象。autoform不會呈現選擇選項字段
我的架構如下所示:
// register collections
Objects = new Mongo.Collection('objects');
ObjectTypes = new Mongo.Collection('objectTypes');
// define schema
var Schemas = {};
Schemas.ObjectType = new SimpleSchema({ // object type schema
name: {
type: String
}
});
Schemas.Object = new SimpleSchema({ // object schema
type: {
type: ObjectTypes.Schema,
optional: true
},
title: {
type: String
}
});
// attach schemas
ObjectTypes.attachSchema(Schemas.ObjectType);
Objects.attachSchema(Schemas.Object);
我自動窗體看起來是這樣的:
{{> quickForm collection="Objects" id="insertTestForm" type="insert"}}
我居然會想到選擇選項字段爲我喜歡的類型屬性,但是,會出現一個文本輸入。有人知道爲什麼
根據文檔[1],它應該是一個選擇選項字段:
If you use a field that has a type that is a Mongo.Collection instance, autoform will automatically provide select options based on _id and name fields from the related Mongo.Collection. You may override with your own options to use a field other than name or to show a limited subset of all documents. You can also use allowedValues to limit which _ids should be shown in the options list.
[1] https://github.com/aldeed/meteor-collection2/blob/master/RELATIONSHIPS.md#user-content-autoform
編輯 如果我使用
type: ObjectTypes,
代替
type: ObjectTypes.Schema,
我的應用程序崩潰,引發了以下錯誤:
Your app is crashing. Here's the latest log.
/Users/XXX/.meteor/packages/meteor-tool/.1.1.3.ik16id++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
throw(ex);
^
RangeError: Maximum call stack size exceeded
Exited with code: 8
Your application is crashing. Waiting for file change.
會拋出一個錯誤,看我更新的問題 – Ronin