我将开始TypeScript在我的HTML客户端项目中使用,该项目属于具有实体框架域模型的MVC项目.我希望我的两个项目(客户端和服务器端)完全分离,因为两个团队将在此工作...... JSON和REST用于来回传递对象.
当然,我domain在客户端的对象应该与服务器端的对象匹配.在过去,我通常手动完成此操作.有没有办法重用我的C#类定义(特别是POJO我的域模型中的类)来在TypeScript中创建相应的类"?
使用knockout mapping插件(http://knockoutjs.com/documentation/plugins-mapping.html)可以映射一个深层次的层次对象吗?
如果我有一个具有多个级别的对象:
var data = {
name: 'Graham',
children: [
{
name: 'Son of Graham',
children: [
{
name: 'Son of Son of Graham',
children: [
{
... and on and on....
}
]
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何在javascript中将其映射到我的自定义类:
var mapping = {
!! your genius solution goes here !!
!! need to create a myCustomPerson object for Graham which has a child myCustomerPerson object
!! containing "Son of Graham" and that child object contains a …Run Code Online (Sandbox Code Playgroud)