我有一个具有数据库导航属性的模型。模型结构如下
public class Parent{
public string propertyone {get; set;}
public IList<Child> children {get; set;}
}
public class Child{
public string propertyone {get; set;}
public string propertytwo {get; set;}
public IList<Seed> children {get; set;}
}
使用 Breeze ,我从数据库加载类型为“Parent”的单个对象,并在表中显示“children”属性。
this.parent= manager.fetchEntityByKey('Parent', 42)
单击按钮后,我想添加另一个 child
<table data-bind="with: parent">
<tr data-bind="foreach: children">
<td data-bind="text: children"></td>
<td data-bind="text: children"></td>
<td><a data-bind="click: $root.remove">Remove</a></td>
</tr>
</table>
<a data-bind="click: $root.add">Add</a>
我的 add 函数不起作用,如下所示,其中 self 代表返回的 View 模型。
function add(parent){
var newchild= ko.observable(entityType.createEntity(
{
propertyone : "Test"
}));
parent.children.push(newchild);
//parent().children().push(newchild);
//self.parent.children.push(newchild);
//self.parent().children().push(newchild);
}
这以及添加函数中的注释行是我尝试过的,但不起作用。我收到错误,未定义不是函数
。如何向此导航集合添加一个表示父实体和子实体之间一对多关系的项目?
最佳答案
如果您的元数据设置正确,您所需要的只是:
entityType.createEntity({ parentIdProperty: 'parent id value' });
这将创建实体并将其添加到父实体的集合中。
关于c# - Breeze js-如何添加新的子实体并将其附加到父级的子实体集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25488839/