我对淘汰赛比较陌生,想知道是否有更好的方法来根据单选按钮组的选择来控制两个 div 元素的可见性。
我想出的东西似乎相当脆弱,如果它们是额外的选项,这个解决方案将无法扩展 imo。
<label>Total</label><input type="radio" name="toggleGraph" value="total" data-bind="checked: toggleGraph" />
<label>Growth</label><input type="radio" name="toggleGraph" value="growth" data-bind="checked: toggleGraph" />
<div id="total-graph" data-bind="visible: $root.toggleGraph() === 'total'">
Total Graph Here
</div>
<div id="growth-graph" data-bind="visible: $root.toggleGraph() === 'growth'">
Growth Graph Here
</div>
var ViewModel = function() {
var self = this;
self.toggleGraph = ko.observable('total');
}
ko.applyBindings(new ViewModel());