Thursday, 15 March 2012

knockout.js - Select2 4.0 and Knockout 3.1 select not allowing selection -


I work with a selection 2 (version 4.0 RC2) trying to get Knockout (version 3.1) I am here.

I am unable to select the input and chose the initial one. Selection seems readable only.

Below is a problem that demonstrates my problem. I tested Chrome on it (version 40.0.2214.115 meters).

Javascript:

  ko.utils.setValue = function (property, newValue)) {If the property (property) property ( New Valley); Other property = new value; }; Ko.bindingHandlers.select2 = {init: function (element, valueAccessor, allBindingsAccessor) {var obj = valueAccessor (), allBindings = allBindingAccessor (), Lookup all = Bindings.lookupKey; $ (Element) .select2 (obj); Ko.utils.registerEventHandler (element, "select2-selected", function (data) {if (allBindingsAccessor () ('selectedValue') {ko.utils.setValue (allBindingsAccessor (). SelectedValue, data.choice);}} ); Ko.utils.domNodeDisposal.addDisposeCallback (element, function) {$ (element) .select2 ('deleted');});}, update: function (element, validator, all binding ester) {var options = all bindings plus (). Select2 Option {different assets in the option} {$ (element) .select2 (property, ko.utils.unwrapObservable (option [Properties]))} $ $ (element). Trigger (' Change ');}}; // for two objects with one object Structurizer = country = function (name, population, value) {this.countryName = name; this.countryPopulation = population; this value = value; this.id = value; this.text = name;}; var country = [ New Country ("UK", 65000000,1), New Country ("USA", 320000000,2), New Country ("Sweden", 290000003)]; Var ViewsModel = {Available Country: K. Ossebel Erray (Country), selected country: K.Aserberval (country [1]); ko.applyBindings (ViewModel);  

HTML:

  Your country : & Lt; Choose style = "width: 100%;" Data-bound = "option: $ root. Available country, option text: 'country name', value: selected country, select2: {}" & gt;  

This is an up-to-date, working Bela:

The main issue you're killing is that Knockout.js binds all the options with the same value attribute, which is empty, and Select2 can not handle it correctly I was able to fix this by entering the optionsValue: 'id' in the data-wrap attribute, which set the value attribute on ID properly did .

The second thing is that selection 2 does not take care of choosing options with value in the same way, about which I have opened a ticket:

< / Div>

No comments:

Post a Comment