2012-05-06 29 views
2

我试图通过流星来创建KineticJS对象的位置更新。通过流星更新KineticJS Canvas元素

看来,麻烦的是:

Players.update({name: "Rect"}, {xpos: this.attrs.x}) 

这里是流星文档说:

// Find the document with id "123", and completely replace it. 
    Users.update({_id: "123"}, {name: "Alice", friends: ["Bob"]}); 

我试图检查,看看是否数据正在通过更新:

console.log(Players.findOne({name: "Rect"}).xpos); 

这是github:

https://github.com/randompast/randomtests/tree/master/meteorCanvasTest

回答

3

首先,总是使用$ set来更新您的属性,以免踩到名称之类的东西。由于您在后续更新中踩过名称,因此没有名称为“rect”的属性需要更新。 Players.update({name: "Rect"}, {$set: {xpos: this.attrs.x}})

if (Meteor.is_client) { 
    Players.find().observe({ 
    changed: function(new_doc, idx, old_doc) { 
     if(MyTest.rect) { 
     MyTest.rect.attrs.x = new_doc.xpos; 
     MyTest.layer.draw(); 
     } 
    }      
    }); 
    .... 

    MyTest.rect.on("dragend", function() { 
     Players.update({name: "Rect"}, {$set: {xpos: this.attrs.x}}); 
    }); 
    .... 

} 

只需插入观察功能,确保您的dragend使用$组符号。