<select data-bind="value: productPrice">
<option data-price="2">Цена $2.00</option>
<option data-price="4">Цена $4.00</option>
</select>
Ваша цена <span data-bind="text: productPrice"></span>
<select data-bind="selectedAttribute: { attr: 'data-price', property: productPrice }">
var viewModel = {
productPrice: ko.observable()
};
ko.bindingHandlers.selectedAttribute = {
init: function(element, valueAccessor) {
var attr = valueAccessor().attr,
property = valueAccessor().property;
function updateModel() {
property(element.options[element.selectedIndex].getAttribute(attr));
}
element.addEventListener('change', updateModel);
updateModel();
}
};
ko.applyBindings(viewModel);