Working with breeze backed by SharePoint, as described here, and using TypeScript rather than JS.
In a DataService class I create an EntityManager and execute a Query:
private servicePath: string = '/api/PATH/';
private manager: breeze.EntityManager;
constructor() {
this.init();
}
private init(): void {
this.manager = new breeze.EntityManager(this.servicePath);
}
public ListResponses(): breeze.Promise {
var query = breeze.EntityQuery.from("Responses");
return this.manager.executeQuery(query);
}
I then call this from my view model, which works fine:
private loadResponses(): void {
this.dataservice.ListResponses().then((data) => {
this.handleResponsesLoaded(data);
}).fail((error) => {
this.handleDataError(error);
});
}
private handleResponsesLoaded(data:any): void {
for (var i = 0; i < results.length; i++){
this.extendItem(results[i]);
}
this.renderList(results, "#tp-responses-list");
}
But my attempt to extend each item fails, because the item's entityAspect
is null:
private extendItem(item: any): void {
item.entityAspect.propertyChanged.subscribe(() => { // FAILS HERE
setTimeout(() => {
if (item.entityAspect.entityState.isModified()) {
this.dataservice.SaveChanges().then((result) => {
tracer.Trace("SaveChanged Result: " + result);
}).fail((error) => {
this.handleDataError(error);
});
}
}, 0);
});
}
Upon inspecting the result item, I can see it's just the plain data object, with all the properties I would expect but no Entity goodness:
I've just started with breeze, so the best way to put the question is probably: what have I done wrong here?