Note that there are some explanatory texts on larger screens.

plurals
  1. PODurandal App - Not reflecting changes in view-model
    primarykey
    data
    text
    <p><strong>EDIT:- I have uploaded complete code for project at <a href="https://github.com/amantur/DurandalTest.git" rel="nofollow">github</a>.</strong></p> <p>Following is my view-model:</p> <pre><code>define(["ko", "service/dataService", 'service/logger', 'durandal/system'], function (ko, svc, logger, system) { var that = this, results = ko.observableArray(), query = ko.observable(); var SearchProduct = { activate: activate, title: 'Search', search: search, results: results, query: query }; return SearchProduct; function activate() {} function search() { svc.searchProduct(query()).then(function (data) { results([]);results(data); }).fail(function (jqXHR, textStatus) { var msg = 'Error searching item: ' + textStatus; logger.logError(msg, jqXHR, system.getModuleId(svc), true); });; } }); </code></pre> <ol> <li>First thing is that in <code>search</code> function, when I call <code>query()</code>, it returns undefined.</li> <li><p>Second when I search and add new items to <code>results</code> with following line:</p> <p>results(data);//data is array of 10 items</p></li> </ol> <p>the changes are not reflected in following html template:</p> <pre><code>&lt;form class="navbar-form pull-right" role="search" data-bind="submit: search"&gt; &lt;div class="form-group"&gt; &lt;input type="text" class="form-control" placeholder="Search" data-bind='text: query, valueUpdate: "afterkeydown"'&gt; &lt;/div&gt; &lt;button type="submit" class="btn btn-default"&gt; &lt;span class="glyphicon glyphicon-search"&gt;&lt;/span&gt;&amp;nbsp;Search &lt;/button&gt; &lt;/form&gt; &lt;section data-bind="foreach: results"&gt; &lt;div class="row"&gt; &lt;div class="col-md-4 pull-left"&gt; &lt;label data-bind="text: name"&gt;&lt;/label&gt;&lt;br/&gt; &lt;label data-bind="text:category"&gt;&lt;/label&gt; &lt;/div&gt; &lt;div class="col-md-7 pull-right"&gt; &lt;label data-bind="text:shortDescription"&gt;&lt;/label&gt; &lt;/div&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p>the <code>section</code> is bound using <code>foreach: results</code>. When after the change is applied (list of items added to observable) and I come to page after navigating from some other page, the following line correctly reflects the count:</p> <pre><code>&lt;span data-bind="text: results().length"&gt;&lt;/span&gt;&amp;nbsp;items found </code></pre> <p>What am I doing wrong?</p> <p><strong>EDIT:-</strong> <em><strong>One part of puzzle is resolved</em></strong></p> <p>If I use <code>results()</code> instead of <code>results</code>, the binding with list works!!!</p> <pre><code>&lt;section data-bind="foreach: results()"&gt; </code></pre> <p><strong>EDIT 3:-</strong> *<em>Created simple <code>cshtml</code> view and used viewmodel there with <code>ko.applyBindings</code> method. It works this way. Seems I am missing some piece of <code>drundal</code> wiring</em>*</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload