angularjs – Angular / Breeze SPA模板上的UnMapped属性
发布时间:2020-12-17 07:48:53 所属栏目:安全 来源:网络整理
导读:我在visual studio 2012中使用Angular / Breeze SPA模板.我在TodoList服务器模型中添加了一个未映射的属性. [NotMapped]public string MyUnmappedProperty{ get{return "testString";}} 我在客户端模型的构造函数中注册了未映射的属性,特别是在Ward建议的tod
我在visual studio 2012中使用Angular / Breeze SPA模板.我在TodoList服务器模型中添加了一个未映射的属性.
[NotMapped] public string MyUnmappedProperty{ get{return "testString";}} 我在客户端模型的构造函数中注册了未映射的属性,特别是在Ward建议的todo.model.js中:Handling calculated properties with breezejs and web api function TodoList() { this.title = "My todos"; // defaults this.userId = "to be replaced"; this.myUnmappedProperty=""; } 当第一次在todo.controller.js上调用getTodos()方法时,“myUnmappedProperty”具有构造函数中设置的空字符串的值.只有在第二次调用getTodos()之后(我添加了一个执行该操作的按钮)并将’forceRefresh’设置为true(getTodos(true))才能查询服务器,只有这样才能看到myUnmappedProperty获取值“的TestString”. 我想知道为什么我会得到这种行为.是否可以在第一次调用getTodos()时使未映射的属性填充服务器值? 谢谢.
你找到了解决这个问题的方法吗?我一直在努力解决同样的问题,最近才发现了CassidyK的
this SO post,他通过改变Breeze源代码(breeze.debug.js)中的一行解决了一个非常类似的问题.这是他改变的代码片段(取自CassidyK的帖子):
proto.initializeFrom = function (rawEntity) { // HACK: // copy unmapped properties from newly created client entity to the rawEntity. // This is so that we don't lose them when we update from the rawEntity to the target. // Something that will occur immediately after this method completes. var that = this; this.entityType.unmappedProperties.forEach(function(prop) { var propName = prop.name; that[propName] = rawEntity[propName]; // CassidyK //rawEntity[propName] = that[propName]; // Breeze }); if (!this._backingStore) { this._backingStore = { }; } }; 我试过这个解决方案,似乎工作得很好.请注意,如果您遇到的服务器端属性未映射到数据库中,并且在客户端创建对象时需要客户端覆盖此值,则此更改可能会让您遇到麻烦. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |