Search code examples
knockout.jsknockout-mvc

using knockout binding


i have database value "active" returning true and false value from sql query . i want the checkbox should be ticked when active =true and unchecked when active=false. i have used mvc model in php

what should i do? its a php page.

  <div class="datagrid">
    <table class="table table-hover table-bordered" id="additionaltable">
        <thead>
            <tr>
                <th class="span1">
                    Questions
                </th>
                <th class="span1">
                    Active
                </th>
            </tr>
        </thead>
        <tbody data-bind="foreach: items">
            <tr data-id="value:id">
                <td data-bind="text:question">
                </td>
                <td>
                    <input type="checkbox" data-bind="checked: active" />
                </td>
            </tr>
        </tbody>
    </table>
</div>

and i have 1 more query ... the table loads up with data .. on clicking in data in table , the values should be displayed in textbox ..what to do for this?


Solution

  • You lines -

    <td data-bind="text:question">
    </td>
    

    Won't work. You have to text bind to a span to get the behavior you want.

    <td> 
       <span data-bind="text:question"></span>
    </td>
    

    I put together a working sample at http://jsfiddle.net/photo_tom/kBKzv/4/