Documentation

include MVC MVC.Animate MVC.Class MVC.Controller MVC.Controller.Action MVC.Controller.Action.Drag MVC.Controller.Action.Drop MVC.Controller.Action.EnterLeave MVC.Controller.Action.Event MVC.Controller.Action.Hover MVC.Controller.Action.Lasso MVC.Controller.Action.Selectable MVC.Controller.Action.Subscribe MVC.Controller.Comet MVC.Controller.Params MVC.Controller.Params.Drag MVC.Controller.Params.Drop MVC.Controller.Stateful MVC.Delegator MVC.Doc MVC.Element MVC.Event MVC.File MVC.History MVC.IO MVC.IO.Ajax MVC.IO.Comet MVC.IO.JsonP MVC.IO.WindowName MVC.IO.XDoc MVC.Model MVC.Model.Ajax MVC.Model.Cookie MVC.Model.JsonP MVC.Model.JsonRest MVC.Model.WindowName MVC.Model.XmlRest MVC.Native MVC.Native.Array MVC.Native.Date MVC.Native.Function MVC.Native.Number MVC.Native.Object MVC.Native.String MVC.Options MVC.Store MVC.SyntheticEvent MVC.Test MVC.Test.Assertions MVC.Test.Controller MVC.Test.Functional MVC.Test.Runner MVC.Test.Unit MVC.Timer MVC.Timer.Easings MVC.Vector MVC.View MVC.View.Helpers OpenAjax

MVC.View

View provides client side templates. Typically they work with controller to render data in HTML form. Typically, you should not be creating and rendering a view with MVC.View, you should be using MVC.Controller.render to create and render templates from your controllers.

Install

 include.plugins('view') //for basic templating functionality
 include.plugins('view/helpers') //for HTML helpers

Including views

MVC can package processed views in the production file. After including the include plugin, you can use include.views wrapped in an include callback function. Because included views are already processed, they don't rely on eval. Here's how to include them:
 include.plugins('view','controller')
 include.controllers('tasks');
 include(function(){
   include.views('views/tasks/show');
 })
Read more about include.views.

View Helpers

View Helpers create html code. View by default only comes with partial and to_text. You can include more with the view/helpers plugin. But, you can easily make your own! Learn how in the Helpers page.

Constructor

MVC.View

new MVC.View(options) -> mvc.view

Creates a new view

{Object} - A hash with the following options
OptionDefaultDescription
url   loads the template from a file. This path should be relative to [MVC.root].
view_url   loads the template from a file. This path should be relative to [MVC.root]/views.
text   uses the provided text as the template. Example:
new View({text: '<%=user%>'})
element   loads a template from the innerHTML or value of the element.
type '<' type of magic tags. Options are '<' or '['
name the element ID or url an optional name that is used for caching.
cache true in production mode, false in other modes true to cache template.

Prototype Methods

render

render(object, extra_helpers) -> String
Renders an object with extra view helpers attached to the view.
{Object} - data to be rendered
{Object} - an object with additonal view helpers
{String} - returns the result of the string

set_options

set_options(options) -> undefined
Sets options on this view to be rendered with.
{Object} -

update

update(element, options) -> null/Function
Updates an element's innerHTML with the rendered view.
{HTMLElement/String} - or id of the element to update
{null/String/Object} - is one of the following nullstringobject
TypeResult
returns a function that takes an object and renders with it to the view
uses the string as a url to perform a get request for JSON data.
uses the object to render
{null/Function} -

Static Methods

MVC.View.config

MVC.View.config(options) -> undefined
Sets default options for all views
{Object} - Set view with the following options
OptionDefaultDescription
type '<' type of magic tags. Options are '<' or '['
cache true in production mode, false in other modes true to cache template.