【问题标题】:Meteor autoform and Collection2 not saving dataMeteor autoform 和 Collection2 不保存数据
【发布时间】:2015-12-30 16:00:42
【问题描述】:

我遇到了 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 文件中发布和订阅集合。这是插入的html代码

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

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

【问题讨论】:

  • 一切对我来说都是正确的。插入后用于显示客户的代码在哪里?
  • 我用meteortoys查看客户是否添加,我使用mongodb cli查看是否添加到集合中。
  • 我也觉得不错。您没有任何错误消息?
  • 无。我没有任何错误消息。我什至将它部署在流星上,它仍然没有保存

标签: meteor meteor-autoform meteor-collection2


【解决方案1】:

我整理好了。集合中的这个字段

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"
		}
	},

是导致问题的原因。谢谢大家的意见

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    相关资源
    最近更新 更多