您可以使用
checked
结合你可以添加一个可观察的
selectedPoint
根据您的javascript,这可能如下所示:
viewModel.selectedPoint = ko.observable();
选中的
绑定到HTML:
<div data-bind="foreach: $parents[1].droppoints" >
<label>
<input class="droppoint_radio" type="radio"
name="droppoint_location"
data-bind="attr: {value: number},
checked: $parents[2].selectedPoint" />
<div class="droppoint_address">
<div data-bind="text: company_name"></div>
</div>
</label>
</div>
最后,将第一个droppoint的数量设置为AJAX回调中的默认值:
$.ajax({
url: '/path/to/external/rest/api/' + zipCode,
type: 'GET',
context: document.body
}).done(
function (response) {
$.each(response, function(key, droppoint) {
self.droppoints.push(droppoint);
});
self.selectedPoint(response[0].number);
}
)