Skip to content

stikjs/stik-view-bag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#$viewBag Enables a controller to push and pull data in and out of its template. While pushing, $viewBag will only care about the values within the object passed.

##Using it For the given HTML:

<div data-controller="MessageCtrl" data-action="Revelation">
  <span data-key="senderName"></span>
  <span data-key="receiverName"></span>
  <span data-key="message"></span>
  <input data-key="customNOOO"/>
</div>

And this JS:

stik.controller("MessageCtrl", "Revelation", function($viewBag){
  // the push method receives an object
  // with the values that it will use
  $viewBag.push({
    senderName: "Darth Vader",
    receiverName: "Luke Skywalker",
    message: "I'm your father!",
    customNOOO: "NOOOOOO!!!"
  });

  // use pull to get bound data out of the template
  var dataset = $viewBag.pull();
  // this will return an object with the following structure
  // {
  //   senderName: "Darth Vader",
  //   receiverName: "Luke Skywalker",
  //   message: "I'm your father!",
  //   customNOOO: "NOOOOOO!!!"
  // }
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published