• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    This module has been deprecated and is no longer supported by the module author.

    Model (gallery-model)

    Last Updated: 08/26/11

    Greg Hinch

    YUI Contributor

    See 14 more by this user.

    Created: 11/1/10
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.4.0
    Free for use.

    When working with complex UI driven applications, sometimes it is useful to have an OO method of dynamically interacting with your data. The Model class is an attempt to bring some useful principles of object relational mapping (at least as I understand them) into YUI. While not necessarily useful unto itself, the Model class forms a good foundation for performing multiple interactions on a single piece of data.

    • Tags:
    • greghinch
    • model
    • data
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    A model is defined as a constructor which extend Y.Model. The ATTRS map is used to define the members of the model, and setters can be used to ensure typing.

    In order to use models easily with a DataSource, the DataSourceModelMapper plugin can be used to easily convert the results array into an array of models. The config for the plugin takes a model constructor and a map, an object in which the keys correspond with members in the model, and the values correspond with paths to the data in a result. Much like the resultLocator in a DataSchema, values are strings and can use dot notation to go multiple levels deep to find data.

    Code Sample

    YUI().use('gallery-model', 'datasource-io', 'datasource-jsonschema', function(Y) {
      var Book = Y.Base.create('book', Y.Model, [], {}, {
        ATTRS : {
          title : {}
          author : {},
          datePublished : {
            setter : "date"
          }
      });
     
      var bookSource = new Y.DataSource.IO({
        source : '/path/to/source.php?'
        plugins : [
          {fn : Y.Plugin.DataSourceJSONSchema, cfg : {
            schema : {
               resultFields : ['title', 'author', 'published']
            }
          }},
          {fn : Y.Plugin.DataSourceModelMapper, cfg : {
            model : Book,
            map : {
              author : 'author',
              title : 'title',
              datePublished : 'published'
            }
          }}
        ]
      });
     
      bookSource.sendRequest({
        request : 'foo=bar',
        callback : {
          success : function (e) {
             var models = e.response.results // will be model instances rather than objects
          }
        }
      });
    });

    Forum Posts

    No forum posts for this module.

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info