Reputation: 211
I'm playing around with the breezejs knockout Todo-list tutorial/template (http://www.asp.net/single-page-application/overview/templates/breezeknockout-template). I decided to make a new Employees class and see if I could bind to a list of employees.
The view references a variable in the VM 'results' which is supposed to be an observable array of employees.
<section data-bind="foreach: results">
<article>
<header>
<form>
<input type="text" data-bind="value: firstName" />
</form>
</header>
</article>
</section>
In the viewmodel I added the result var and a line in order to automatically load employees into the results variable.
/* Defines the Todo application ViewModel */
window.todoApp.todoListViewModel = (function (ko, datacontext) {
var results = ko.observableArray();
var todoLists = ko.observableArray(),
error = ko.observable(),
viewmodel = {
showTestPage: showTestPage,
results: results,
todoLists: todoLists,
error: error,
addTodoList: addTodoList,
deleteTodoList: deleteTodoList,
clearErrorMessage: clearErrorMessage,
searchTerms: ko.observable(""),
performSearch: performSearch
};
// load todoLists immediately
datacontext.getTodoLists(todoLists, error);
// load employees
datacontext.getEmployees(results, error);
return viewmodel;
Here is my datacontext function
function getEmployees(empObservable, errorObservable)
{
return breeze.EntityQuery
.from("Employees")
.where('lastName', 'startsWith', 'G')
.orderBy("lastName")
.using(manager).execute()
.then(getSucceeded)
.fail(getFailed);
function getSucceeded(data) {
empObservable(data.results);
}
function getFailed(error) {
errorObservable("This is broke *BREAK*" + error.message + "*BREAK*");
}
}
The fail occurs and the error.message I see includes the data that I should be getting in my results. It's even ordered and filtered correctly, though I'm only showing one record below as an example. I don't get any other error messages.
This is broke *BREAK*[{"$id":"1","$type":"ToDoBreeze.Models.Employee, ToDoBreeze","ID":"12345","LastName":"Gaston","FirstName":"Jake"}]*BREAK*
I don't suppose anyone else messing around with this template has had a similar problem?
Upvotes: 0
Views: 48
Reputation: 211
Took me a while to find the right words for this question to come up, but it looks like this is the answer. I guess I'll leave mine up in case someone else finds it. (Query failed and the error.message is the data)
Basically, I had something in my employee initializer in the model that should not have been there.
Upvotes: 1