breezejs - How to initiate complex type properties when creating a new Entity

帅比萌擦擦* 提交于 2019-12-11 09:59:03

问题


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

I created a new Entity of person with this code :

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

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

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.


回答1:


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);


来源:https://stackoverflow.com/questions/17538542/breezejs-how-to-initiate-complex-type-properties-when-creating-a-new-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!