Thanks for the great idea! Each of the fields in a row has some metadata associated with it already provides the type of its value (date, string, number, collection, etc) and I'm already swapping out the editing template, so this worked nicely. Here's what I'm doing now:
I have the ScalarValue, DateValue, ArrayValue, etc, set up as you describe. My row is now defined as having
field: ko.observable()
operator: ko.observable()
_value: ko.observable()
value: ko.computed(function() {
return _value().toValueArray();
})
In my view model, I'm using the convention of a leading _ to filter things out that I don't want serialized to JSON, so the end result is exactly what I was looking for originally. My template binding is a little strange, in that I now have to do:
<input data-bind="_value().startDate" />
<input data-bind="_value().endDate" />
The one trick, is that since a user can select and change the field in a row, I'm using Knockout's manual subscription feature to subscribe to the field's change event and then swapping the value observable's inner type. Overall, it seems to be working great.