Retrieve Text and Value from Select with KENDO MVVM

1

I need help from vcs, anyone who has knowledge on KnockoutJS

I have something like this:

var viewModelPessoa = kendo.observable({
    Contatos: [],
    FormContato: {
        TipoContato: -1, //Aqui vai o indice/value do select/option
        TipoContatoTexto: null, //Aqui vai o text do select/option
    },
    AddToContato: function() {
         this.get("Contatos").push({
            TipoContato: this.get("FormContato.TipoContato"),
            TipoContatoTexto: this.get("FormContato.TipoContatoTexto"),
         });
    }
});

And on my page I have the following:

<select id="listaTipoContatos" data-bind="value: FormContato.TipoContato">
    <option value="-1"> Não informado </option>
    <option value="0"> Telefone Residencial </option>
    <option value="1"> Telefone Comercial </option>
</select>

How do I? I put something like <select id="listaTipoContatos" data-bind="value: FormContato.TipoContato,text: FormContato.TipoContatoTexto"> ?

    
asked by anonymous 27.03.2014 / 16:07

1 answer

1

The correct binding syntax for a select, according to Knockout documentation , looks like this:

<select data-bind="options: availableCountries,
                   optionsText: function(item) {
                       return item.countryName + ' (pop: ' + item.countryPopulation + ')'
                   },
                   value: selectedCountry,
                   optionsCaption: 'Choose...'"></select>

I have no experience with Kendo, but I imagine that in this case you should pass the "Contacts" in options , and specify the right attributes to use as value .

    
27.03.2014 / 16:30