<small id='bpZfE'></small><noframes id='bpZfE'>

      • <bdo id='bpZfE'></bdo><ul id='bpZfE'></ul>
    1. <i id='bpZfE'><tr id='bpZfE'><dt id='bpZfE'><q id='bpZfE'><span id='bpZfE'><b id='bpZfE'><form id='bpZfE'><ins id='bpZfE'></ins><ul id='bpZfE'></ul><sub id='bpZfE'></sub></form><legend id='bpZfE'></legend><bdo id='bpZfE'><pre id='bpZfE'><center id='bpZfE'></center></pre></bdo></b><th id='bpZfE'></th></span></q></dt></tr></i><div id='bpZfE'><tfoot id='bpZfE'></tfoot><dl id='bpZfE'><fieldset id='bpZfE'></fieldset></dl></div>

    2. <tfoot id='bpZfE'></tfoot>
      <legend id='bpZfE'><style id='bpZfE'><dir id='bpZfE'><q id='bpZfE'></q></dir></style></legend>

      Knockout observable 可以数据绑定到单选按钮的值吗?

      时间:2023-10-20

          <small id='mWkvA'></small><noframes id='mWkvA'>

            <bdo id='mWkvA'></bdo><ul id='mWkvA'></ul>
            <i id='mWkvA'><tr id='mWkvA'><dt id='mWkvA'><q id='mWkvA'><span id='mWkvA'><b id='mWkvA'><form id='mWkvA'><ins id='mWkvA'></ins><ul id='mWkvA'></ul><sub id='mWkvA'></sub></form><legend id='mWkvA'></legend><bdo id='mWkvA'><pre id='mWkvA'><center id='mWkvA'></center></pre></bdo></b><th id='mWkvA'></th></span></q></dt></tr></i><div id='mWkvA'><tfoot id='mWkvA'></tfoot><dl id='mWkvA'><fieldset id='mWkvA'></fieldset></dl></div>
            <tfoot id='mWkvA'></tfoot>

          • <legend id='mWkvA'><style id='mWkvA'><dir id='mWkvA'><q id='mWkvA'></q></dir></style></legend>
              <tbody id='mWkvA'></tbody>
              • 本文介绍了Knockout observable 可以数据绑定到单选按钮的值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否可以使用值绑定将 Knockout 可观察属性绑定到单选按钮?

                Is it possible to bind a Knockout observable property to a radio button using a value binding?

                这是我想要做的,但值最终是字符串[Object object]",而不是我的可观察属性的实际实例:

                Here's what I'm trying to do, but the value ends up being the string "[Object object]" instead of the actual instance of my observable property:

                <input type="radio" name="vehicleGroup" data-bind="checked: vehicleGroupViewModel().selectedGroupOption , value:vehicleGroupViewModel().car" />
                
                <input type="radio" name="vehicleGroup" data-bind="checked: vehicleGroupViewModel().selectedGroupOption , value:vehicleGroupViewModel().truck" />
                

                这是我正在使用的视图模型:

                Here's the view models I'm using:

                var VehicleGroupViewModel = function(){
                    var self = this;
                    this.selectedVehicleGroup = ko.observable();
                    this.selectedGroupOption = ko.observable();
                    this.selectedGroupOption.subscribe(function (newVal) {
                        self.selectedVehicleGroup(newVal);
                    }
                    this.selectedGroup = ko.observable();
                    this.car = ko.observable(new VehicleViewModel());
                    this.truck = ko.observable(new VehicleViewModel());
                }
                
                var VehicleViewModel = function(){
                    this.name = ko.observable();
                }
                

                所以最后我希望 Car 或 Truck VehicleViewModel 在 selectedVehicleGroup observable 中.

                So in the end I would like either the Car or Truck VehicleViewModel to be in the selectedVehicleGroup observable.

                推荐答案

                如文档所述这里只有 Select 节点能够将任意 JavaScript 对象绑定到一个值.其他输入需要一个字符串值,这就是您的值返回[Object object]"的原因.

                As documented here only Select nodes have the ability to bind an arbitrary JavaScript object to a value. Other inputs require a string value, which is why your value is returning "[Object object]".

                你仍然可以做你想做的事,但你必须手动映射一个键并自己找到合适的对象.这是一个演示的小提琴:

                You can still do what you want but you will have to manually map a key and find the appropriate object yourself. Here is a fiddle that demonstrates:

                http://jsfiddle.net/jearles/JcPXy/

                这篇关于Knockout observable 可以数据绑定到单选按钮的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:JavaScript 读取 IE 和 FireFox 中的单选按钮值 下一篇:如何要求以 html5 形式选择单选按钮

                相关文章

                1. <tfoot id='89AMx'></tfoot>

                      <bdo id='89AMx'></bdo><ul id='89AMx'></ul>

                    <small id='89AMx'></small><noframes id='89AMx'>

                  1. <i id='89AMx'><tr id='89AMx'><dt id='89AMx'><q id='89AMx'><span id='89AMx'><b id='89AMx'><form id='89AMx'><ins id='89AMx'></ins><ul id='89AMx'></ul><sub id='89AMx'></sub></form><legend id='89AMx'></legend><bdo id='89AMx'><pre id='89AMx'><center id='89AMx'></center></pre></bdo></b><th id='89AMx'></th></span></q></dt></tr></i><div id='89AMx'><tfoot id='89AMx'></tfoot><dl id='89AMx'><fieldset id='89AMx'></fieldset></dl></div>
                    <legend id='89AMx'><style id='89AMx'><dir id='89AMx'><q id='89AMx'></q></dir></style></legend>