灰烬模型计算,服务器或客户端?(Ember model computation, server or client?)

编程入门 行业动态 更新时间:2024-10-28 03:22:12
灰烬模型计算,服务器或客户端?(Ember model computation, server or client?)

我有一个存储在服务器上的简单模型:

1.服务器型号(或夹具)

availableHours:[{from,to},...] holidays:[{from, to},...] sales:[{from, to},...]

然而,在客户端上,这变成了一个相当复杂的2d矩阵,显示时间重叠,基于用户选择的不同渲染,所以在我解析和计算它之后的客户端,它看起来像这样:

2.客户端模型

[ [{date:11/09, from:09:00, to:17:00, tags:['sales']}, {date:11/10, from:09:00, to:17:00, tags:[]} ], //.... ]

基本上是一个2d矩阵,一个时间跨度(从今天到用户选择的任何时间),我可以拍到桌子上,这是一个类似日历的UI,可以随着模型的变化自动渲染和更新。 所以现在当我检索下一组数据(#1)时,我在客户端上计算它以生成客户端模型(#2)。

检查Ember文档(入门),好像我必须在服务器上计算#2模型并将其发送给客户端。 这看起来与原始数据一样,因为您可以看到它更小,非常适合通过互联网发送。 第二个数据更大,但非常适合渲染到表格中。

我应该在ember,#1还是#2中定义什么样的模型结构? 如果它是#1,我如何计算并映射它以在用户进行更改时自动更改视图。

I have a simple model that's stored on server:

1. Server model (or fixture)

availableHours:[{from,to},...] holidays:[{from, to},...] sales:[{from, to},...]

On the client however this turns into a rather complex 2d matrix, showing the time overlaps, different renderings based on user selection, so on the client after I parse and compute it, it would look like this:

2. Client model

[ [{date:11/09, from:09:00, to:17:00, tags:['sales']}, {date:11/10, from:09:00, to:17:00, tags:[]} ], //.... ]

Basically a 2d matrix, a time span (from today to whatever user selects), that I can slap onto a table, a calendar-like UI that renders and updates itself automatically as the model changes. So now when I retrieve the next set of data (#1), I calculate it on the client to produce the client model (#2).

Checking the Ember docs (getting started), It seems as if I'd had to compute the #2 model on the server and send it to client. This seems as on overhead as the original data, as you can see is much smaller, perfect for sending over the internet. The second data is bigger, yet perfect for rendering into a table.

What should I define as my model structure in ember, #1 or #2? And if it's #1, how do I compute and map it to auto change the view as the user makes changes.

最满意答案

虽然你的帖子对我来说不太清楚,但这是我的理解。

我更喜欢第一种方式,因为它更清洁。

availableHours:[{from,to},...] holidays:[{from, to},...] sales:[{from, to},...]

如何在用户进行更改时计算并映射它以自动更改视图。

正如您在帖子中所说,计算将在客户端进行,以retrieve第二组data 。 您可以通过valueBinding属性将视图绑定到模型,该属性会在模型更改时自动更改视图。

您还可以使用computed properties来聆听模型中发生的更改

Though your post is not so clear to me, here is my understanding.

I would prefer the first way as its more cleaner approach.

availableHours:[{from,to},...] holidays:[{from, to},...] sales:[{from, to},...]

how do I compute and map it to auto change the view as the user makes changes.

As you said in your post, computation would happen in the client side to retrieve the second set of data. You can bind your view to model through the valueBinding property which would make the auto changes to your view as your model changes.

You can also use computed properties to listen to the changes happening in your model

更多推荐

本文发布于:2023-07-30 08:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:灰烬   客户端   模型   服务器   Ember

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!