【发布时间】:2014-09-11 05:49:39
【问题描述】:
出于某种奇怪的原因,我的 .update 函数无法正常运行。我认为this._id 的选择器是这里的问题,但我尝试传入数据库中一个项目的原始 ID。使用good_input,.insert 的内容全部存储在数据库中,但.update 只是跳过查看结果。
Template.newInstitution.events({
'click #form_institution': function () {
var inst_name = $('#name')[0].value;
var inst_type = $('#type')[0].value;
var inst_school = $('#school')[0].value;
var inst_desc = $('#description')[0].value;
var good_input = true;
if (inst_name === "") {
$('#name')[0].placeholder = "Please enter a name";
$('#nameDiv').addClass("has-error");
good_input = false;
}
if (inst_type === "") {
$('#type')[0].placeholder = "Please enter a type";
$('#typeDiv').addClass("has-error");
good_input = false;
}
if (inst_school === "") {
$('#school')[0].placeholder = "Please enter your affiliated school";
$('#schoolDiv').addClass("has-error");
good_input = false;
}
if (inst_desc === "") {
$('#description')[0].placeholder = "Please enter a description";
$('#descDiv').addClass("has-error");
good_input = false;
}
if (good_input) {
Institutions.insert({
admin: Meteor.userId(),
title: inst_name,
type: inst_type,
school: inst_school,
description: inst_desc
});
Institutions.update({_id: this._id},
{$push: {
members: Meteor.userId()
}}
);
Router.go('songs');
}
}
});
https://bpaste.net/show/befaba419c19
有人会在这里找出问题并解释原因吗?
【问题讨论】:
-
bpaste.net/show/8bc51e4e8a4b -- 这是来自 js 文件但与此模板无关的其他一些相关 sn-ps。
标签: javascript jquery mongodb meteor