微风不会产生ko可观测值 [英] Breeze does not generate ko observables
问题描述
我在使用简单的MVC4 + ko +微风webapp时遇到以下问题: 查询返回的微风实体是简单的javascript对象,没有ko可观察的对象. 我检查了待办事项示例(正确返回ko可观察值),但没有找到将微风配置为与ko配合使用(并生成可观察值)的地方. 我尝试添加以下几行,但未更改:
I have the following problem with a simple MVC4 + ko + breeze webapp: the breeze entities returned by a query are simple javascript objects, without ko observables. I inspected the todo sample (which correctly returnes ko observables) and I didn't find the place where breeze is configured to work with ko (and generate observables). I tried adding the following lines, but nothing changed:
var core = breeze.core;
var entityModel = breeze.entityModel;
core.config.setProperties({
trackingImplementation: entityModel.entityTracking_ko,
remoteAccessImplementation: entityModel.remoteAccess_webApi
});
在此先感谢您的帮助
推荐答案
陷阱! 问题出在WebApi控制器中缺少几个属性:
gotcha! the problem was in a couple of missing attributes in the WebApi controller:
[JsonFormatter, ODataActionFilter]
public class MyController : ApiController
{
// my methods...
}
添加[JsonFormatter,ODataActionFilter]后,返回的实体具有预期的ko可观察值!
After adding [JsonFormatter, ODataActionFilter] the returned entities had the expected ko observables!
这篇关于微风不会产生ko可观测值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!