2

I have this code as global for the whole page:

<script type="text/javascript">
    var data = [];
    var VM_FiltroSeguros =
        {
            seguros: ko.observableArray(data)
        };
    ko.applyBindings(VM_FiltroSeguros.seguros);
</script>

Then when a succesfull ajax call is made, executed this:

function okFiltrarSeguros(data)
    {
        var parsedData = parse(data);
        if (parsedData.Ok)
        {
            toastr.success('Se encontraron ' + parsedData.Value.length.toString() + ' Seguros.');

            $('#liResultsFiltroSeguro').show();

            VM_FiltroSeguros.seguros = parsedData.Value;
};

The Html is these:

<table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Ramo</th>
                            <th>Poliza</th>
                        </tr>
                   </thead>
                   <tbody data-bind="foreach: seguros">
                     <tr>
                       <td><span data-bind="text: NroRamo"></span></td>
                       <td><span data-bind="text: NroSeguro"></span></td>
                     </tr>
                   </tbody>
                  </table>

After VM_FiltroSeguros.seguros = parsedData.Value; is executed I can see in the debugger that the viewModel is filled whith objects, but the is never updated. What could be wrong? Thanks!!!!

1 Answer 1

4

There's a couple of things you're doing wrong here. First, you need to bind the entire ViewModel:

var data = [];
var VM_FiltroSeguros =
{
   seguros: ko.observableArray(data)
};
ko.applyBindings(VM_FiltroSeguros);

Then you need to add data to the 'seguros' property with a function call like this:

VM_FiltroSeguros.seguros(parsedData.Value);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, at first i tried your code and didn't worked either. But the i tried to put the code inside <body> and not in <head> and it works!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.