简体   繁体   English

我需要使用JavaScript可视化动态集合,可以使用Reactive Extensions实现它吗?

[英]I need to visualize a dynamic collection with JavaScript, can it be implemented with Reactive Extensions?

I am writing this Web application where I need to visualize filtered, sorted and paginated (on the server) collections through JavaScript (planning on using Isotope to present collections). 我正在编写此Web应用程序,在这里我需要通过JavaScript(计划使用Isotope呈现集合)来可视化(在服务器上)过滤,排序和分页的集合。 These collections are dynamic, ie they start out with certain items, but their content may change throughout the application's lifetime. 这些集合是动态的,即它们从某些项目开始,但是它们的内容可能会在应用程序的整个生命周期中发生变化。 Could I implement this functionality by watching a collection on the server through Reactive Extensions for JavaScript? 是否可以通过Reactive Extensions for JavaScript在服务器上查看集合来实现此功能? If so, how? 如果是这样,怎么办?

Example

For this particular problem, let's say a collection is rendered in HTML as an element #container with a child element of class item for each collection item: 对于这个特定问题,假设一个集合以HTML呈现为元素#container ,并且每个集合项都有类item的子元素:

<div id="container">
  <div class="item">Item 1</div>
  <div class="item">Item 3</div>
</div>

If "Item 2" is then added to the collection and "Item 1" removed from it on the server, JavaScript should react by rendering the updated collection as follows to HTML: 如果随后在服务器上将“ Item 2”添加到集合中并从其中删除“ Item 1”,则JavaScript应该通过将更新的集合呈现为HTML来做出反应:

<div id="container">
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>

I've created an animated fiddle to demonstrate this sort of scenario. 我创建了一个动画小提琴来演示这种情况。 Imagine that the changes to the collection take place on the server, and that the JavaScript simply reacts to it. 想象一下,对集合的更改发生在服务器上,而JavaScript只是对此做出了反应。

I've found that Reactive Extensions may help in solving this problem, but it doesn't concern itself with communication between the server and client. 我发现Reactive Extensions可能有助于解决此问题,但它与服务器和客户端之间的通信无关。 A likely way to apply RX would be to establish a bridge between server and client, through which RX events could flow. 应用RX的一种可能方法是在服务器和客户端之间建立桥梁,RX事件可以通过该桥梁流动。 SignalR stands out as a likely option for implementing the bridge. SignalR是实现桥接的可能选择。 There even exists a project, SignalR.Reactive , which combines SignalR and RX in this way. 甚至存在一个名为SignalR.Reactive的项目,该项目以这种方式结合了SignalR和RX。

The real problem in solving my problem, I think, will be how to publish changes on the server. 我认为,解决我的问题的真正问题是如何在服务器上发布更改。 I've found out that RavenDB, which is my database of choice, has an API for observing changes to data, so hopefully I'll be able to design a scheme around this. 我发现RavenDB是我选择的数据库,它具有用于观察数据更改的API,因此希望我能够围绕此设计一个方案。 Once this is solved, I envision the publishing of changes to clients being fairly trivial with the help of RX and SignalR. 解决此问题后,我设想借助RX和SignalR将更改发布到客户端变得微不足道。

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

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