简体   繁体   English

具有角色和状态的Ember.js模型架构

[英]Ember.js Model architecture with roles and states

I am currently diving into Ember.js. 我目前正在研究Ember.js。 I have started a new project which should handle todo tasks. 我已经开始了一个新的项目,应该可以处理待办事项。

However I have some problems in translating the database architecture and/or OOP architecture to an ember model architecture. 但是,在将数据库体系结构和/或OOP体系结构转换为余烬模型体系结构时,我遇到了一些问题。

What I would like to have is: 我想拥有的是:

A task which has the following attributes: 具有以下属性的任务:

  • id
  • title
  • state ('open', 'closed') state (“打开”,“关闭”)
  • editor
  • creator
  • createdAt
  • modifiedAt

The point were I stuck is: 我坚持的重点是:

  • how to abstract the state (in OOP I would create a struct for this) 如何抽象状态(在OOP中,我将为此创建一个结构)
  • how to abstract the editor/creator thing 如何抽象编辑器/创建器的东西

I would be glad if anyone would have a suggestion for me since the Ember.js documentation only covers basic use cases and is lack of things like states. 我很高兴有人对我提出建议,因为Ember.js文档仅涵盖基本用例,并且缺少诸如状态之类的东西。

Well actually Ember is OOP, just to mention that first! 好吧,实际上Ember是OOP,首先要提到!

Now lets talk about your editor / editor . 现在让我们谈谈您的editor editor I would recommend to basically create another model person , and then you could so something like this: 我建议基本上创建另一个模型person ,然后可以这样:

creator: belongsTo('person'),
author: belongsTo('person'),

You don't need an inverse relationship so this will basically just work, as long you don't want to find all task 's one person has created or so. 您不需要逆向关系,因此只要您不想找到一个人创建的所有task ,就可以正常工作。

For the state you basically have three ways: 对于state您基本上有以下三种方式:

  1. What I recommend is to use another model for this, and use a belongsTo relationship. 我建议为此使用另一种模型,并使用belongsTo关系。 But this is not a good way if you want to execute different code on different states. 但这不是一个好方法,如果您想在不同的状态下执行不同的代码。 But the best if you want to have a dropdown or so to select the state . 但是最好是如果要下拉菜单选择state
  2. You could just sent the strings. 您可以发送字符串。
  3. You could sent integers and have somewhere a mapping to the values. 您可以发送整数,并在某处具有到值的映射。 Like an object or an map, to map the integers to the strings. 像对象或地图一样,将整数映射到字符串。

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

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