codepb/jquery-template

Set selected in Option

Closed this issue · 2 comments

How can i set selected for option, according json value?
I saw a sample in stackoverflow like this:

json:
"dados":[{"nome":"Maria Silva","l_Sexo":"F"}]"

  <'div class="wrp-inp">
        <label for="genero">Gênero:</label>
        <span class="icon-chevron-down"></span>
        <select class="" name="genero" >
            <option value="M" {{if l_Sexo == 'M'}}selected{{/if}}>Male</option>
            <option value="F" {{if l_Sexo == 'F'}}selected{{/if}}>Female</option>
        </select>
    </div'>

But didn't work.

After ask in stackoverflow, i found this solution: http://stackoverflow.com/a/33500209/1095530
Is the better way?

Thanks

your option is currently the best solution. There is a bug that needs fixing with binding to the value on a select box.

Thanks!