Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting koGrid to work with Breeze and Durandal HotTowel template
    text
    copied!<p>I have a Durandal widget (hot towel template) containing a koGrid which I'm trying to bind to my view model. </p> <p>I'm pretty new to these technologies, including async deferreds and promises, so please forgive my ignorance of such matters!</p> <p>The view model gets its data from a datacontext class which simply returns the results of a Breeze entity manager query (which returns a Q promise):</p> <pre><code> var manager = new breeze.EntityManager({ dataService: dataService }); return manager.executeQuery(query) .then(function (data) { return data.results; }) .fail(queryFailed); </code></pre> <p>In the constructor of my widget, I have:</p> <pre><code>var vm = function(element, settings) { var self = this; this.settings = settings; this.myData = ko.observableArray([]); this.viewAttached = viewAttached; queryDataContext.executeQuery('Customer', 'good').then(function(ents) { var Item = function(id, name, maincontacttelephone) { this.ID = id; this.Name = name; this.MainContactTelephone = maincontacttelephone; }; for (var i = 0; i &lt; ents.length; i++) { self.myData.push(new Item(ents[i].ID(), ents[i].Name(), ents[i].MainContactTelephone())); } self.gridOptions = { data: self.myData }; }); }; return vm; function viewAttached(view) { $(window).trigger('resize'); return true; } </code></pre> <p>The data comes back in the "ents" variable, gets pushed into the observableArray myData, and that should work...however an error occurs in the koGrid file:</p> <pre><code> /*********************************************** * FILE: ..\src\bindingHandlers\ko-grid.js ***********************************************/ ko.bindingHandlers['koGrid'] = (function () { return { 'init': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var options = valueAccessor(); </code></pre> <p>valueAccessor() is undefined, which prevents the grid from working.</p> <p>Now if I change my code which executes the remote query to:</p> <pre><code>$.when(queryDataContext.executeQuery('Customer', 'good')).then(function(ents) { </code></pre> <p>(using a jQuery promises when), it works for some reason. However the ents variable is then of type 'makePromise' which I'm not sure how to resolve.</p> <p>From my understanding it's a Q promise which Breeze returns anyway, and if I use</p> <p>Q.when(queryDataContext.executeQuery('Customer', 'good')).then(function(ents) {</p> <p>then ents contains the data, but I'm back to the koGrid undefined problem again.</p> <p>Any help much appreciated!</p>
 

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