敲出双向左侧和顶部绑定(Knockout two-way left and top binding)

众所周知, 如何通过击倒来绑定左侧和顶部 。

但它允许仅在一个方向上设置值(模型到视图)。

如何保持双向绑定,这样当我改变对象的位置(拖放)时,它在模型中是实际的(视图到模型)?

如果淘汰不可能,那么实施它的最佳方法是什么?

It's known how to bind left and top by knockout.

But it allows to set a value in one direction only (model-to-view).

How can I keep two-way binding, so that when I change the position of an object (drag-and-drop) it will be actual in the model (view-to-model)?

If it isn't possible by knockout, how is the best way to implement it?

最满意答案

基本上你需要创建一个自定义绑定。 创建一个接受该位置的绑定,然后在绑定中创建一个事件处理程序来监听位置何时更改并将更改写回最初传递的属性

这篇博文应该有所帮助

http://www.alexjamesbrown.com/blog/development/using-custom-options-with-knockoutjs-drag-and-drop/

basically you will need to create a custom binding. Create a binding that accepts to the position, then in the binding create an event handler to listen for when the positions changed and write the changes back to the properties originally passed

This blog post should help

http://www.alexjamesbrown.com/blog/development/using-custom-options-with-knockoutjs-drag-and-drop/

敲出双向左侧和顶部绑定(Knockout two-way left and top binding)

众所周知, 如何通过击倒来绑定左侧和顶部 。

但它允许仅在一个方向上设置值(模型到视图)。

如何保持双向绑定,这样当我改变对象的位置(拖放)时,它在模型中是实际的(视图到模型)?

如果淘汰不可能,那么实施它的最佳方法是什么?

It's known how to bind left and top by knockout.

But it allows to set a value in one direction only (model-to-view).

How can I keep two-way binding, so that when I change the position of an object (drag-and-drop) it will be actual in the model (view-to-model)?

If it isn't possible by knockout, how is the best way to implement it?

最满意答案

基本上你需要创建一个自定义绑定。 创建一个接受该位置的绑定,然后在绑定中创建一个事件处理程序来监听位置何时更改并将更改写回最初传递的属性

这篇博文应该有所帮助

http://www.alexjamesbrown.com/blog/development/using-custom-options-with-knockoutjs-drag-and-drop/

basically you will need to create a custom binding. Create a binding that accepts to the position, then in the binding create an event handler to listen for when the positions changed and write the changes back to the properties originally passed

This blog post should help

http://www.alexjamesbrown.com/blog/development/using-custom-options-with-knockoutjs-drag-and-drop/