javascript - Breeze.js query not updating knockout view at all -
javascript - Breeze.js query not updating knockout view at all -
i'm new breeze , struggling having results of breeze query linked knockout observable array , array not updating view when populated. found this questoin, similar problem, mine won't bind first time around. did seek of things suggested in thread, though, no luck.
i've been working off of breeze.js todo demo (here). using console.log, info coming query looking same info demo code. query pulling list of breweries table i'm trying, now, bind list (eventually drop-down). there tiny thing i'm missing here? thanks, in advance, help!
view model code:
viewmodel = (function () { var self = this; self.breweries = ko.observablearray(); function getbreweries() { dataservice().getbreweries().then(querysucceeded).fail(queryfailed); function querysucceeded(data) { self.breweries(data.results); } function queryfailed(error) { alert(error); } } getbreweries(); }); ko.applybindings(viewmodel);
dataservice code (in separate file, data's coming out of fine):
dataservice = (function () { var servicename = '/breeze/beermatch/'; //route breeze web api controller var manager = new breeze.entitymanager(servicename); homecoming { getbreweries: getbreweries }; function getbreweries() { var query = breeze.entityquery.from("breweries"); homecoming manager.executequery(query); } });
and, finally, front-end code seek , bind list:
<script src="~/scripts/jquery-2.1.3.js" type="text/javascript"></script> <script src="~/scripts/q.js" type="text/javascript"></script> <script src="~/scripts/knockout-3.3.0.js" type="text/javascript"></script> <script src="~/scripts/breeze.min.js" type="text/javascript" ></script> <script src="~/scripts/app/dataservice.js" type="text/javascript"></script> <script src="~/scripts/app/viewmodel.js" type="text/javascript"></script> <div> <div class="row" id="home"> <ul id="breweries" data-bind="foreach: breweries"> <li> <span data-bind="text: breweryname"></span> </li> </ul> </div> </div>
i'm not 100% sure why worked, moved of script declarations bottom of index.cshtml file (they declared @ top, outside of tag.
putting them @ bottom, outside main container s, in the same order in in original post fixed problem , binding alright. thanks, all!
javascript entity-framework knockout.js breeze
Comments
Post a Comment