所以我已经用meteor写了一个相当大的应用程序,只是添加了minimongoid包。我知道它喜欢first()而不是findOne(),create()而不是insert(),但是我不知道如何更新文档。我正在尝试执行以下操作,但它显示了下面的错误...我做错了什么?
Transactions.update {_id: txn._id},
$set:
"isActive": false
TypeError: Object function Transactions() {
I20140302-18:22:54.226(-5)? return Transactions.__super__.constructor.apply(this, arguments);
I20140302-18:22:54.226(-5)? } has no method 'update'我的postings.coffee里只有
class @Transactions extends Minimongoid
@_collection: new Meteor.Collection('transactions')发布于 2014-03-19 19:10:06
使用minimongoid可以更新对象实例,而不是使用Class方法。
如下所示:
aTransaction = Transaction.create({-some attributes-})
aTransaction.update({attributeName: attributeValue})发布于 2014-06-26 21:32:09
我仍然是MeteorJS的新手,但让我试试吧。我花了一段时间才自己弄明白。幸好我们在工作中使用RoR。我要做的是:
在服务器JavaScript上:(如果您使用Rails,这应该很容易获得。)
Meteor.methods
updateTransaction: (id, name, url) ->
Transaction.find(id).update(
"isActive": status
)然后在我的客户机上模板( JavaScript ):
Template.transaction_template.events
'submit .transaction-form': (event, template)->
event.preventDefault() // if using an <a>, remove is using button with type=button
status = template.find('[name=status]').value // find the input form with the name=status
Meteor.call 'updateTransaction', { id: @_id, status }https://stackoverflow.com/questions/22135101
复制相似问题