【发布时间】:2016-10-26 05:42:07
【问题描述】:
大家好,请告诉我为什么我不能更新我的子文档。我可以更新普通文档字段,但不能更新子文档,我在这里硬编码了方法,只是为了让它工作。
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import './Months.js';
export const Product = new Mongo.Collection('product');
ProductItem = new SimpleSchema({
author: {
type: String,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
fileId: {
type: String,
autoValue: function() {
return this._id
},
autoform: {
type: "hidden"
}
},
name: {
type: String
},
sellingPrice: {
type: Months,
autoform: {
type: "hidden"
},
},
purchasePrice: {
type: Months,
autoform: {
type: "hidden"
},
}
});
Product.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return !!userId;
},
update: function (userId, doc) {
// can only change your own documents
return !!userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
Meteor.methods({
updateProduct: function(id, newVal, target, inner) {
console.log(id + "" + target);
Product.update(id, {
$set: {'sellingPrice.$.M1': 10 },
});
},
});
Product.attachSchema( ProductItem );
我也试过了
Meteor.methods({
updateProduct: function(id, newVal, target, inner) {
console.log(id + "" + target);
Product.update(id, {
$set: {'sellingPrice.$': {'M1': 10} },
});
},
});
还有
Meteor.methods({
updateProduct: function(id, newVal, target, inner) {
console.log(id + "" + target);
Product.update(id, {
$set: {'sellingPrice.M1': 10 },
});
},
});
仍然注意到,nada。
月
从 'meteor/mongo' 导入 { Mongo }; 从“流星/检查”导入{检查};
Months = new SimpleSchema({
M0: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
},
},
M1: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
},
},
M2: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M3: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M4: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M5: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M6: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M7: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M8: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M9: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M10: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
M11: {
type: Number,
autoValue: function() {
return 0;
},
autoform: {
type: "hidden"
}
},
});
所以任何帮助都会非常感谢
【问题讨论】:
-
能否添加 Months.js 架构?
-
嘿@andresk 谢谢你的回复