如何强制同一应用(DNN/2sxc)的两个实例从同一流中读取? [英] How to force two instance of the same app (DNN/2sxc) to read from the same stream?

查看:45
本文介绍了如何强制同一应用(DNN/2sxc)的两个实例从同一流中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果我的问题很愚蠢,但是我是DNN/2sxc的新手,我整天都在努力解决这个问题,但没有成功..

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..

我有同一个应用程序的两个实例,一个在主页上,另一个在自己的页面上,每个实例必须有自己的视图模板(我使用Razor).

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

我的问题是我无法找到使两个应用读取相同数据的方法,因此其中一个的每个添加/编辑/删除/重新排序都会反映到另一个,目前每个应用都有自己的数据因此,在我的情况下,它们将无法使用.

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.

我尝试在数据查询"中使用"EntityTypeFilter"并在两个视图中使用它(就像在News-Simple演示视频中一样),它起作用了,并且给了我两个视图中的所有项目,但是此解决方案带来了另外两个问题:

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:

1-现在,我无法使用工具栏(添加/删除/重新排序等)任何项,如您在

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,

注意:这是我使用的工具栏:

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-内容演示项目"在列表中也可见,但是并不是很重要,因为我可以删除它并使用真实数据项中的一个作为演示项目.

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.

我非常感谢您的帮助.谢谢.

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

因此,当您需要手动轻松地控制显示的确切项目,它们的订购等"时.您想使用"content-assigned-to-instance",它还为您提供了简单的添加,删除按钮,因为这些按钮实际上并未删除任何内容,而只是从module-instance中删除了分配.

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.

现在您的情况有点特殊,因为您想在另一个模块实例中重用完全相同的集合.有几种方法可以做到这一点:

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:

相同视图

如果它是完全相同的视图,等等.只需使用DNN功能(将添加模块添加到另一个页面)来复制该模块

if it's exactly the same view etc. just duplicate the module using DNN-features (the add-existing-module-to-another page)

不同的视图

如果是其他视图(可能更紧凑等),您将再次有多个选择.第一种是使用dnn功能镜像/复制,然后仅将if-im放在此页面上然后以不同的方式显示或注入另一个CSS.没有任何开发诀窍,这可能是最简单的.

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. That's probably the easiest without any dev-know-how.

更难但可能更好的方法是实际使用一个新模板,并告诉它以在其他模块中配置它们的方式检索项目-假设模块1是原始模板,模块2有一个模板希望以与1中给出的完全相同的顺序访问模块1的项目的不同模板.它们的执行方式很简单,但是在模块2中需要几行C#代码.

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.

您需要创建一个新的ModuleDataSource( https://2sxc.org/en/Docs/Feature/feature/4542 )对象,并告诉它它来自模块1.如果您从未做过,基本上就是您的代码可以像可视化设计器一样创建查询,但是您还有更多控制-请参见Wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All .visual-query-designer中的Module-Data-Source不允许您切换"模块(我们可能会在将来添加一个高级设置),但是该对象具有ModuleId属性,您可以在访问数据之前对其进行设置,使其切换"到该模块.这是Module#2剃须刀中的伪代码...

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. 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. here's the Pseudo code in your Module#2 razor...

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

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

应该这样做:)

这篇关于如何强制同一应用(DNN/2sxc)的两个实例从同一流中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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