breezejs-创建新实体时如何初始化复杂类型属性 [英] breezejs - How to initiate complex type properties when creating a new Entity

查看:88
本文介绍了breezejs-创建新实体时如何初始化复杂类型属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有人类型具有一些复杂的属性,例如Address和dateOfBirth

Suppose there is person type which has some complex properties such as Address and dateOfBirth

我使用以下代码创建了一个新的person实体:

I created a new Entity of person with this code :

 newPerson(manager.createEntity("Person",{ id: breeze.core.getUuid() }));

如何初始化复杂类型,以便将其绑定到空白表格?
在微风的文档中显示: http://www.breezejs.com/documentation/ complextype-properties

How can I initiate the complex type so I can bind it to a blank form? In the breeze doc it says :http://www.breezejs.com/documentation/complextype-properties


这实际上有点不正确,您可以创建complexType的未绑定
实例使用complexType.createInstance方法
,但是在分配它时,您只是将其值复制到
现有实例中。

This is actually slightly incorrect, you can create an ‘unbound’ instance of a complexType with the complexType.createInstance method but when you assign it, you are simply copying its values onto an existing instance.

哪里是初始化复杂类型属性的最佳位置?任何示例代码都将非常有用。

Where is the best place to initiate the complex type properties?any sample code would be so helpful.

推荐答案

如果您正在处理标量导航属性,即返回另一个实体的单个实例的导航属性,那么您可以在createEntity调用中正确执行

If you are dealing with a scalar navigation property, i.e. a navigation property that returns a single instance of another entity, then you can do it right in the createEntity call

 newDetail = manager.createEntity("OrderDetail", { Order: parentOrder, Product: parentProduct });

如果您要处理非标量(即数组)导航属性,则需要推动子级进入导航属性。即

If you are dealing with a nonscalar (i.e. array) navigation property then you will need to push the children into the navigation property. i.e.

 newCustomer = em.createEntity("Customer");
 var orders = newCustomer.getProperty("Orders"); 
 orders.push(order1);
 orders.push(order2);
 // OR
 // orders.push.apply(orders, ordersToPush);

这篇关于breezejs-创建新实体时如何初始化复杂类型属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆