以下のコードは、render関数内のBackbone.Viewにあります。Backbone.RelationalとjQueryUISortableを使用しています。
var scopedThis = this;
// make this container a sortable container
this.$el.sortable({
connectWith: '.wlProductsInRoomContainer',
revert: true,
stop: function(){
scopedThis.getNewSortOrders();
},
receive: function(e, r){
// get model from newly passed in product
var prodModel = r.item.data().productView.model;
// add model to this collection but pass silent so collection add event doesn't get ran
scopedThis.collection.add(prodModel, { silent: true });
},
remove: function (e, r){
// get model from product that has left this sortable
var prodModel = r.item.data().productView.model;
// remove this model from this collection
scopedThis.collection.remove(prodModel);
console.log(scopedThis.collection);
}
});
問題は、ソート可能な削除機能で発生しています。ソート可能ファイルを離れた要素には、対応するモデルが.data()に含まれています。そこで、そこから取得してこのコレクションから削除しようとしますが、後でコレクションをログに記録すると、モデルが削除されることはありません。これを特に奇妙なものにしているのは、同じ正確なモデルを使用して追加するその上の受信関数が完全に機能することです。何か案は?私は助けに感謝します!