Meteor autoform和Collection2不保存数据

时间:2015-12-30 16:00:42

标签: meteor meteor-autoform meteor-collection2

我遇到了Collection2和autoform的问题。这是我的收藏

Customers = new Mongo.Collection("customers");

Customers.allow({
	insert: function(userId, doc) {		
		return !!userId;
	}
});

CustomerSchema = new SimpleSchema({
	name: {
		type: String,
		label: "Name"
	},
	address: {
		type: String,
		label: "Address"
	},
	amount: {
		type: Number,
		label: "Amount"
	},
	bvn: {
		type: String,
		label: "BVN"
	},
	type: {
		type: String,
		label: "Sale Type"
	},
	saleDate: {
		type: Date,
		label: "Transaction Date",
		autoValue: function() {
			return new Date()
		},
		autoform: {
			type: "hidden"
		}
	},
	passport: {
		type: String,
		label: "Passport Number"
	},
	source: {
		type: String,
		label: "Source"
	},
	tickets: {
		type: Boolean,
		label: "Tickets"
	},
	visa: {
		type: Boolean,
		label: "Visa"
	},
	invoice: {
		type: Boolean,
		label: "Invoice"
	},
	nextSaleDate: {
		type: Date,
		label: "Next Sale Date",
		autoValue: function () {
			var thisDate = new Date();
			var dd = thisDate.getDate();
			var mm = thisDate.getMonth() + 3;
			var y = thisDate.getFullYear();

			var nextDate = dd + '/'+ mm + '/'+ y;
			return nextDate;
		},
		autoform: {
		type: "hidden"
		}
	},
	author: {
		type: String,
		label: "Author",
		autoValue: function () {
			return this.userId
		},
		autoform: {
		type: "hidden"
		}
	}	

});
Customers.attachSchema(CustomerSchema);

我已经分别使用方法Meteor.publish('customers', function() { return Customers.find({author: this.userId}); });Meteor.subscribe("customers");在单独的发布和订阅javascript文件中发布和订阅了这些集合。这是插入的

<template name="NewCustomer">
	<div class="new-customer">
		{{>quickForm collection="Customers" id="insertCustomerForm" type="insert" class="new-customer-form"}}
	</div>
</template>

但是当我启动服务器并添加新客户时,它不起作用。谁能帮我吗?谢谢

1 个答案:

答案 0 :(得分:0)

我整理出来了。集合中的此字段

&#13;
&#13;
nextSaleDate: {
		type: Date,
		label: "Next Sale Date",
		autoValue: function () {
			var thisDate = new Date();
			var dd = thisDate.getDate();
			var mm = thisDate.getMonth() + 3;
			var y = thisDate.getFullYear();

			var nextDate = dd + '/'+ mm + '/'+ y;
			return nextDate;
		},
		autoform: {
		type: "hidden"
		}
	},
&#13;
&#13;
&#13;

是导致问题的那个。谢谢大家的意见