AngularJS模型 [英] AngularJS Models

查看:130
本文介绍了AngularJS模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图环绕AngularJS我的头。我喜欢了很多,但是核心理念似乎是逃避我? - 在哪里车型

I'm trying to wrap my head around AngularJS. I'm liking a lot of it, but a core concept seems to be escaping me – where are the models?

如果我有一个应用程序,例如,显示交易的多个列表。一个列表中可查询分页的配套标准的一些事务的服务器,其他列表采用了不同的标准,但也有可能同时匹配标准和名单都结束了,一些交易。现在:

If I have an application, for example, that displays multiple lists of transactions. One list queries a server for a paginated set of transactions matching some criteria, the other list uses a different criteria, but there may be some transactions that match both criteria and end up in both lists. Now:


  1. 这同时出现在名单应该在这两个范围相同的对象,合适的交易?这难道不是数据绑定的大抽奖,所以在一个地方的更新将在其他镜像?

  1. transactions that appear in both lists should be the SAME object in both scopes, right? Isn't that the big draw of data bindings, so an update in one place will be mirrored in the other?

交易可能有抽象的原始服务器API请求复杂的行为,需要后续查询到服务器以收集更多的数据,手表本身的变化和自身标记为脏,哪里一切去了?

transactions might have complex behaviors abstracting raw server API requests, require subsequent queries to a server to gather more data, watch itself for changes and mark itself as dirty, where does all that go?

列出自己需要知道什么时候一个交易已被去除,所以在一个列表中删除相同的事务会从另一个消失。

lists themselves need to know when a transaction has been removed, so the same transaction deleted in one list will disappear from another.

我们可能要缓存的交易客户端存储的一些味道?

we might want to cache transactions in some flavor of client-side storage?

于是问题又来了:如果这一切去了?是否都得到bunged在$ rootScope和控制器来控制?委托给服务?

So the question again: Where does all this go? Does it all get bunged in the $rootScope and controlled with controllers? Delegated to a service?

在这里的任何方向,无论多么模糊,将AP preciated。

Any direction here, no matter how vague, would be appreciated.

推荐答案

有关角的事情是,它留下的模型给你。你不必延长一些内置的对象,使其工作,它可以是任何你想要的对象。

The thing about Angular is that it leaves the model up to you. You don't have to extend some built in object to make it work, it can be any object you want.

A)是的,但就像我说的,这是给你的。你甚至可以使用中枢模型实现,如果你愿意的话。

a) Yes, but like I said, that's up to you. You can even use Backbones model implementation if you'd like.

二)大概在你的模型对象。角提供您可以使用的资源服务。您可以定义在这些资源上你自己的方法,这样会是一个很好的起点。

b) Probably in your model object. Angular offers a resource service which you can use. You can define your own methods on those resources, so that'd be a good starting point.

C)你的意思是GUI部分或业务逻辑?角处理GUI为您服务。刚刚实施从列表中删除交易功能,并且角度将重新呈现给你。

c) Do you mean the GUI part or business logic? Angular handles the GUI for you. Just implement the function that removes the transaction from the list, and Angular will re-render it for you.

D)再次,这是由你来实现,或者使用一个库。角主要是关于您模型/持久性层很少发表意见提供了GUI框架。

d) Again, that's up to you to implement or use a library for. Angular is mostly a GUI framework with very little opinion about your model/persistance layer.

有关你的最后一个问题;您会将大部分的逻辑的服务。您的角度控制器将与他们所需要的服务被注入,并揭露功能通过范围视图。你应该避免添加的东西根范围内尽可能多的,因为它们实际上都是在你的模板的全局。

For your last question; you would place most of the logic in services. Your Angular controllers would be injected with the services they need, and expose functionality to the view through the scope. You should avoid adding things to the root scope as much as possible, since they will essentially be global in your templates.

这篇关于AngularJS模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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