我有一个数据库,其中包含具有属性orgref,parentorgref,名称的组织表。
{ orgref: 1, name: "Level 0 org" }
{ orgref: 2, parentorgref: 1, name: "Level 1 org A" }
{ orgref: 3, parentorgref: 1, name: "Level 1 org B" }
{ orgref: 4, parentorgref: 3, name: "Level 2 org" }
我将这些组织存储在rxjs实体状态中。
在我的应用程序的大多数地方,我想分层使用它们(数据树等),因此希望将它们安排为:
{
orgref: 1,
name: "Level 0 org",
children: [{
orgref: 2,
parentorgref: 1,
name: "Level 1 org A"
}, {
orgref: 3,
parentorgref: 1,
name: "Level 1 org B",
children: [{
orgref: 4,
parentorgref: 3,
name: "Level 2 org",
}]
}]
}
当然,如果我通过加载组织时将子组织添加到children
集合中,则
{
...org,
children: getChildrenRecursive()
}
然后断开对实体的引用-也就是说,如果我用orgref = 3编辑实体,它将不会更新层次结构中的组织,因为它是对象的副本,而不是对对象的引用
在ngrx EntityState中处理分层实体是否存在公认的解决方案?
谢谢
答案 0 :(得分:0)
请看一下node_t *new_node(char *text) {
assert( text != NULL);
node_t *temp = (node_t *)emalloc(sizeof(node_t));
strncpy(temp->text, text, LIST_MAXLEN_TEXT);
temp->next = NULL;
return temp;
}
:https://www.npmjs.com/package/ngrx-entity-relationship。
它可以帮助您解决问题。
您的选择器如下所示:
CheckoutGitBranch("some-branch");
// Don't know how your extension is acquiring VS services, you can do this however you want.
// Including using MEF, grabbing it during package initialization etc.
// Whichever method grabs this service does need to be on the UI thread though.
var operationProgress= await _serviceProvider.GetServiceAsync<SVsOperationProgress, IVsOperationProgressStatusService>(throwOnFailure: true);
IVsOperationProgressStageStatus intellisenseStatus = operationProgress.GetStageStatus(CommonOperationProgressStageIds.Intellisense);
await intellisenseStatus.WaitForCompletionAsync();
AnalyzeCodeInWorkspace();
,然后在组件/服务中:
ngrx-entity-relationship
答案 1 :(得分:0)
最佳做法是使您的状态保持不变,并且对数据进行标准化。
选择器负责查询/选择状态幻灯片,并在必要时进行一些汇总。
更新非常容易,简单,而且只有事实来源。
有关Redux模式,请参见this question and answer。