1

ボタンがクリックされる前であっても、何らかの理由で以下のコードがあり、バインディングが行われます。基本的に、ボタンをクリックした後にテーブルを表示したいのですが、ページが読み込まれるとすぐにバインドされます。ここで何が間違っていますか?

JS コード

<script type="text/javascript">
 ShowHideDiv=ko.observable(false);
 function GetResults() {
    alert("test");  //<-- both alerts show as soon as the page loads
    self.ShowHideDiv(true);
    alert(ShowHideDiv()); 
 }

  $(document).ready(function () {
     ko.applyBindings(new GetResults());
  });
</script>

HTML

<input type="button"  id="btnSearch" value="Search" style="margin-left:60px;margin-top:20px" tabindex="8" data-bind="click: GetResults" />


<div id="SearchResult" data-bind="visible: ShowHideDiv">
    <table width="100%" id="tblSearchResults">
    <thead>
        <tr>
            <th>Child Name</th>
            <th>Date</th>
        </tr>
    </thead>

    <tbody>
     <!-- to bind results here -->
    </tbody>

    </table>
</div>
4

1 に答える 1