简体   繁体   中英

Is there anything similar to ActiveModel for CoffeeScript or JavaScript?

I creating a new web site in Rails but I would like to give CoffeeScript/Node.JS a try, and the first thing I would like to do is validations, callbacks and associations on model classes in CoffeeScript (server-side). (maybe a more Domain-driven framework than Rails... =])

Is there something I could use?

Tks

update/more info : The thing is that I'm having problem building a model for a domain that it is more complex than the general domains (eg. blog/cms sample) in Rails. It seems that the DB-driven models in Rails and how it is coupled with DB functions isn't helping me on design my complex domain scenario (a more pure OO + model helpers like ActiveModel would help here).

There are quite a few choices. Various JavaScript frameworks will include something similar to ActiveModel, but that would be the model side only. They would also most likely come with something for views and controllers too, completing MVC.

Here's a small list of frameworks that I know of,

If you're looking for a way to validate models from a Node.js server the way you would with ActiveModel, you should look at this question:Validation library for Node.js

If you want client-side validation, there are many libraries (just Google "js validation library"); perhaps the most mature and feature-rich is jQuery Validation . It's form-oriented rather than model-oriented, but you should be able to map models and forms to each other fairly easily. Of course, in principle you can run any client-side JS library on Node.js, and Rails for that matter (see my RailsConf talk End-to-End CoffeeScript ), using jsdom —a technique that I hope will take off in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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