1
js-model cheatsheet
source link: https://devhints.io/js-model
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Example
Project = Model "project", ->
@extend
findByTitle: (title) -> ...
@include
markAsDone: -> ...
# ActiveRecord::Base.include_root_in_json = false
project = Project.find(1)
project = Project.findByTitle("hello")
project.markAsDone()
Persistence
Project "hi", ->
@persistence Model.REST, "/projects"
@persistence Model.localStorage
Project.load ->
# loaded
Attrs
project = new Project(name: "Hello")
project.attr('name', "Hey")
project.attr('name')
project.save()
project.destroy()
Collection
Food.add(egg)
Food.all()
Food.select (food) -> ...
Food.first()
Food.find(id)
Events
# Classes
Project.bind "add", (obj) ->
Project.bind "remove", (obj) ->
# Instances
project.bind "update", ->
project.bind "destroy", ->
project.trigger "turn_blue"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK