我正在使用Breeze建立一个新的Ng 1项目。我需要向某些实体添加客户端属性。我添加了一个构造函数,但它没有被调用。我添加了一个帖子初始化程序,它也没有被调用。
// a convention can self-register as the default
breeze.NamingConvention.camelCase.setAsDefault();
// create a manager to execute queries
service.manager = new breeze.EntityManager("/api/pts");
// access to the manager's store to add custom client-side properties ..
service.metastore = service.manager.metadataStore;
// entities with client-side properties ..
service.metastore.registerEntityTypeCtor('PtsWine__Pts_BreezeModel', PtsWine, ptsWineInitializer);
var PtsWine = function () {
debugger;
this.uiDayUid = 0;
}
var ptsWineInitializer = function (pw) {
debugger;
pw.uiDayUid = 0;
}
var query = new service.EntityQuery().from("Wines");
return service.manager.executeQuery(query)
.then(function (d) {
debugger;
/// ??? examining d.results shows 40 PtsWine__Pts_BreezeModel entities but
/// constructor and initializer above were never invoked .. ???
})
.fail(function (response) {
toastr.error("Server Error: failed to retrieve listing.")
});
答案 0 :(得分:0)
初始化序列对我来说似乎不正确。在执行registerEntityTypeCtor时,PtsWine和ptsWineInitializer是未定义的。还记得javascript提升概念吗? https://developer.mozilla.org/en-US/docs/Glossary/Hoisting
您需要在调用registerEntityTypeCtor之前定义变量。