<script src='https://cdn.rawgit.com/DroopyTersen/droopy-binding/master/dist/droopy-binding.polyfill.js'></script>
<div id='container' data-id='{{id}}' style='visibility: {{visibility}}'>
Some text here for id: {{id}}
<h1>{{title}}</h1>
<p>{{details}}</p>
<strong>Author: {{author.firstName}} {{author.lastName}}</strong>
<br/>
<strong>Selected: {{selectedItem}}</strong>
<p>Here is an array of complex objects</p>
<ul data-each='complexItems'>
<li>{[name]}</li>
</ul>
<hr/>
<h4>Check out the 2 way binding</h4>
<div style='margin-top:40px'>
<label>Title:</label>
<input id='titleTextBox' value='{{title}}' />
</div>
<div style='margin-top:40px'>
<label>Author Last Name:</label>
<input id='authorTextBox' value='{{author.lastName}}' />
</div>
<br/>
<label>Select an item:</label>
<select value='{{selectedItem}}' data-each='stringItems'>
<option value='{[_]}'>{[_]}</option>
</select>
<br/>
</div>
JavaScript
// setup the initial object to bind to
var model = {
id: 123,
title: "Initial Title",
details: "These are the details",
visibility: "visible",
author: {
firstName: "Andrew",
lastName: "Petersen",
id: "12"
},
stringItems: [
"one",
"two",
"three",
"four"
],
complexItems: [
{
name: "itemOne",
id: 1
}, {
name: "itemTwo",
id:2
}
],
selectedItem: "-1",
};
// create the binding and call 'init()' to display the default values
var binding = new DroopyBinding('container', model);
// Pretend we made an async ajax request and got new property values for our model
// The 'title' and 'details' will automatically update in the view
// No UI code required
setTimeout(function(){
model.title = "My Title",
model.details = "This simulates data changing after an async ajax request";
model.complexItems[0].name = "I'm an array item nested property!";
model.complexItems.push({name: "And I'm a whole new item"});
}, 2000);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.