我正在努力建立这个:

当我在左侧编辑字段时,它应该更新右边的字段,反之亦然.
在输入字段中编辑值会导致文本光标在其末尾跳转.
在华氏温度字段中键入"2"将替换为1.999999999999,如屏幕截图所示.这是因为双重转换:
视图的Fº→模型的Cº→视图的Fº.

我怎么能避免这种情况?
更新:
我想知道在Backbone.js等MVC框架中处理双向绑定的优雅方式.
var Temperature = Backbone.Model.extend({
defaults: {
celsius: 0
},
fahrenheit: function(value) {
if (typeof value == 'undefined') {
return this.c2f(this.get('celsius'));
}
value = parseFloat(value);
this.set('celsius', this.f2c(value));
},
c2f: function(c) {
return 9/5 * c + 32;
},
f2c: function(f) {
return 5/9 * (f - 32);
}
});
var TemperatureView = Backbone.View.extend({
el: document.body,
model: new Temperature(),
events: {
"input #celsius": "updateCelsius",
"input #fahrenheit": "updateFahrenheit"
},
initialize: function() {
this.listenTo(this.model, …Run Code Online (Sandbox Code Playgroud) data-binding model-view-controller model-binding backbone.js