locked
Can not bind value in html table RRS feed

  • Question

  • User631634524 posted

    Hi all,

    I am creating a single page application using knockout and asp.net webmethod.

    When in js class, i make an ajax call to webmethod i can not get the value in htmt table.

    here is my js code for ajax call to web method

    Sammy(function () {
    
            this.get('#:days', function () {
                debugger;
                self.choosenDateId(this.params.days);
                $.ajax({
                    type: "POST",
                    url: 'SinglePageApp.aspx/GetGoals',
                    data: "{goalDate:'" + this.params.days + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert("success");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                        alert(errorThrown);
                    }
                })
            });
            this.get('', function () { this.app.runRoute('get', "#"+new Date()) });
        }).run();

    And here is my html code

    <table class="goals" data-bind="with: choosenDateGoal">
                <thead>
                    <tr>
                        <th>Status</th>
                        <th>Goals</th>
                        <th>Notes</th>
                    </tr>
                </thead>
                <tbody data-bind="foreach: GetGoals">
                    <tr">
                        <td data-bind="text: status"></td>
                        <td data-bind="text: goals"></td>
                        <td data-bind="text: notes"></td>
                    </tr>
                </tbody>
            </table>

    Actually in js success, i can not bind status,goals and notes value. i have put web method name here

    <tbody data-bind="foreach: GetGoals">, sothat its not working. so what should i put here.

    Please help.


    Wednesday, October 3, 2012 2:25 AM

All replies

  • User-129899387 posted

    Hi,

    I'm not sure what problem you actually have, because you didn't post all relevant information.

    So I'll try to guess:

    1. You probably already have 

    ko.applyBindings(myViewModel);

    which binds your knockout object (myViewModel) with your view.

    2. Your viewModel has GetGoals array whose each element has status, goals and notes values.

    All of these variables have to be observable: GetGoals as observable array and even all of these children: status, goals and notes have to be observable itself.

    3. You need change values in your viewModel using data from ajax response.

    If everything I mentioned is already set up, then try to describe your problem in detail here, or you can try to post your problem  on knockoutjs' forum

    Hope it helps.


     

     

    Sunday, November 4, 2012 5:04 PM