【发布时间】:2014-05-23 00:54:52
【问题描述】:
我对 BreezeJS 很陌生,我做错了什么,但不确定是什么。我正在为我的 GET 请求使用第 3 方 API,并使用我自己的服务器后端来处理 SaveChanges 以将每个请求单独触发到第 3 方,因为我无法将 post/put 请求自定义为确切的语法和 post 数据格式我需要。
我们的模型是动态的(意味着客户可以添加新的属性/字段,然后从其余 api 流向我们的客户端),这就是为什么代码如下所示,这就是控制器:
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
var context = JsonConvert.DeserializeObject<List<dynamic>>(saveBundle.SelectToken("entities").ToString());
foreach (var entity in context)
{
foreach (JProperty obj in entity)
{
if (obj != null)
{
// nothing right now but in future persist somehow
}
}
}
// Construct the save result to inform the client that the server has completed the save operation
var keyMappings = new List<KeyMapping>();
return new SaveResult()
{
Entities = context.Cast<object>().ToList(),
Errors = null,
KeyMappings = keyMappings
};
}
调用堆栈如下所示:
TypeError: undefined is not a function
at http://localhost:5749/Scripts/breeze.debug.js:14114:51
at http://localhost:5749/Scripts/breeze.debug.js:235:26
at Array.map (native)
at __map (http://localhost:5749/Scripts/breeze.debug.js:234:15)
at proto.visitAndMerge (http://localhost:5749/Scripts/breeze.debug.js:14111:16)
at http://localhost:5749/Scripts/breeze.debug.js:12806:48
at __using (http://localhost:5749/Scripts/breeze.debug.js:395:16)
at Object.processSavedEntities (http://localhost:5749/Scripts/breeze.debug.js:12794:13)
at saveSuccess (http://localhost:5749/Scripts/breeze.debug.js:12776:67)
at deferred.promise.then.wrappedCallback (http://localhost:5749/Scripts/angular.js:11046:81) undefined
我在 proto.visitAndMerge 中追踪到这一行(breeze.debug.js 中的第 14114 行): if (node.entityAspect.entityState.isDeleted()) {
如果您认为我在做一些愚蠢的事情,我也会全神贯注。可以修改第三方 API 以相应地执行 GET,但据我所知,没有什么可以处理 SaveChanges 捆绑包。
任何建议都会很棒。
作为参考,我试图遵循这种模式:Breezejs SaveChanges: is it possible to return a custom SaveResult object, somehow?
【问题讨论】:
-
嗯,它与动态反序列化有关:JsonConvert.DeserializeObject
- > 但我不会为此提供模型,所以我真的不知道我可以在这里做什么或为什么通过反序列化,它似乎失去了 entityAspect 的属性。