【问题标题】:Updating a KineticJS Canvas element via Meteor通过 Meteor 更新 KineticJS Canvas 元素
【发布时间】:2012-05-15 02:27:06
【问题描述】:

我正在尝试通过 Meteor 更新 KineticJS 对象的位置。

看来问题出在:

  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

【问题讨论】:

    标签: javascript mongodb canvas meteor kineticjs


    【解决方案1】:

    首先,总是使用 $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 使用 $set 表示法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 2014-05-14
      • 2014-10-30
      • 2017-09-14
      • 1970-01-01
      • 2011-06-29
      相关资源
      最近更新 更多