2012-05-06 2 views
2

私はMeteor経由でKineticJSオブジェクトの位置更新をしようとしています。Meteorを介してKineticJS Canvas要素を更新する

トラブルがでていることが表示されます:

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

は、私は、データを介して、更新されたかどうかを確認してみました:

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

ここで流星のドキュメントが言うことです

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イベントが$セット表記を使用していることを確認してください。

関連する問題