简体   繁体   English

如何强制同一应用程序(DNN / 2sxc)的两个实例从同一流中读取?

[英]How to force two instance of the same app (DNN/2sxc) to read from the same stream?

Sorry if my question is silly but I'm new to DNN/2sxc, I've spent the whole day trying to figure this with no success.. 抱歉,如果我的问题很愚蠢,但是我是DNN / 2sxc的新手,我整天都在努力解决这个问题,但没有成功。

I have two instances of the same app, one in the home page and the other on its own page, each one must have its own view template (I use Razor). 我有同一个应用程序的两个实例,一个在主页上,另一个在自己的页面上,每个实例必须有自己的视图模板(我使用Razor)。

My problem is I cannot figure a way to make the two apps read the same data, so every add/edit/remove/re-sort in one of them will be reflected to the other, currently each app has its own data and therefore they are unusable in my case. 我的问题是我无法找到使两个应用程序读取相同数据的方法,因此其中一个应用程序中的每个添加/编辑/删除/重新排序都将反映给另一个应用程序,当前每个应用程序都有自己的数据,因此它们在我的情况下是无法使用的。

I've tried to use a 'EntityTypeFilter' inside a 'Data Query' and use it in both views (as in the News-Simple demo video), it worked and gave me all the items in the two views, but another two problems come with this solution: 我尝试在“数据查询”中使用“ EntityTypeFilter”并在两个视图中使用它(如在News-Simple演示视频中一样),它可以正常工作,并且在两个视图中都提供了所有项目,但是还有两个问题附带此解决方案:

1- now I'm unable to use the toolbar to (add/remove/reorder,.. etc) any of the items , as you can see in this image , which is a show-stopper for me, 1-现在,我无法使用工具栏(添加/删除/重新排序等)任何项,如您在此图像中所看到的,这对我来说是个停滞点,

note: this is the toolbar I use: 注意:这是我使用的工具栏:

@foreach(var item in AsDynamic(Data["Default"]))
{
...
@Edit.Toolbar(target: item, actions: "new,edit,replace,remove,moveup,movedown,instance-list")

2- the 'Content Demo Item' is also visible in the list, but it is not that important since I can delete it and use one of the real data items as a demo item. 2-“内容演示项目”在列表中也可见,但是并不是很重要,因为我可以删除它并使用其中一个真实数据项作为演示项目。

I appreciate any kind of help. 我感谢任何帮助。 Thank you. 谢谢。

So the first thing you should know is the difference when using content-items as data (to query, etc.) and when using it as assigned-items (where each module-instance has a subset of items). 因此,您应该知道的第一件事是将内容项用作数据(以进行查询等)与将其用作分配项(每个模块实例具有项的子集)时的区别。 Here's the blog that should help you understand the difference: http://2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content 这是应该帮助您理解差异的博客: http : //2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content

So when you want the "manually and easily control the exact items displayed, their ordering etc." 因此,当您需要“手动轻松控制显示的确切项目,它们的订购等”时。 you want to use the "content-assigned-to-instance" which also gives you the simple add, delete buttons, as these don't really delete anything, but just remove the assignment from the module-instance. 您想使用“ content-assigned-to-instance”,它还为您提供了简单的添加,删除按钮,因为这些按钮实际上并不会删除任何内容,而只是从模块实例中删除分配。

Now your case is a bit special, in that you want to re-use the exact same set in another module-instance. 现在您的情况有点特殊,因为您想在另一个模块实例中重复使用完全相同的集合。 There are a few ways you can do this: 有几种方法可以执行此操作:

Same View 相同视图

if it's exactly the same view etc. just duplicate the module using DNN-features (the add-existing-module-to-another page) 如果它是完全相同的视图,等等。只需使用DNN功能复制模块(将模块添加到另一个页面)

different view 不同的看法

if it's a different view (maybe more compact, etc.) you again have multiple options. 如果是不同的视图(可能更紧凑等),您将再次有多个选择。 The first is to mirror / duplicate using the dnn-feature, and just put an if-im-on-this-page-then-show-differently or inject another CSS. 第一种是使用dnn功能镜像/复制,然后仅将if-im放在此页面上然后以不同方式显示或注入另一个CSS。 That's probably the easiest without any dev-know-how. 没有任何开发诀窍,这可能是最简单的。

The harder, but possibly nicer way, is to actually to use a new template, and tell it to retrieve the items in the way they are configured in the other module - let's say module 1 is the original, module 2 has a different template wanting to access the items of module 1 in exactly the same order as given in 1. They way to do this is simple, but requires a few lines of C# code in Module 2. 较难但可能更好的方法是实际使用新模板,并告诉它以在其他模块中配置项目的方式来检索项目-假设模块1是原始模板,模块2具有想要的其他模板可以按照与1中给定的完全相同的顺序访问模块1的项目。这样做的方法很简单,但是在模块2中需要几行C#代码。

You need to create a new ModuleDataSource ( https://2sxc.org/en/Docs/Feature/feature/4542 ) object and tell it that it's from Module 1. If you've never done this, it's basically that your code can create a query just like the visual designer, but you have more control - see the wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All . 您需要创建一个新的ModuleDataSource( https://2sxc.org/en/Docs/Feature/feature/4542 )对象,并告诉它它来自模块1。如果您从未做过,基本上就是您的代码可以与视觉设计器一样创建一个查询,但是您拥有更多控制权-请参见Wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All The Module-Data-Source in the visual-query-designer doesn't allow you to "switch" modules (a advanced setting we may add in the future) but the object has a ModuleId property which you can set before accessing the data, making it "switch" to that Module. visual-query-designer中的Module-Data-Source不允许您“切换”模块(我们可能会在将来添加一个高级设置),但是该对象具有ModuleId属性,可以在访问数据之前对其进行设置,使其“切换”到该模块。 here's the Pseudo code in your Module#2 razor... 这是Module#2剃须刀中的伪代码...

var otherModData = CreateSource<ModuleDataSource>();
otherModData.ModuleId = 1;

foreach(var itm in AsDynamic(otherModData["Default"])) {
    ...
}

That should do it :) 那应该做的:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM