2

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

4

1 に答える 1

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}});
    });
  ....

}

その監視関数を挿入し、ドラッグエンドが$set表記を使用していることを確認してください。

于 2012-05-08T05:02:23.437 に答える