Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ken107/databind-js

A powerful and flexible MVC data binding library
https://github.com/ken107/databind-js

data-binding javascript mvc mvc-framework web-component

Last synced: about 2 months ago
JSON representation

A powerful and flexible MVC data binding library

Awesome Lists containing this project

README

        

## What's This?
Data binding allows you to detect changes to your data and react by updating the DOM.

## Installation
First add databind.js to your page.
```html

```
Or `bower install databinder`.

## Detecting Changes To Your Data
Your data is whatever `this` points to, which is by the default the `window` object. Say your window object has the following property:
```javascript
window.blog = {
name: "My blog",
entries: [
{ title: "...", text: "...", isPublished: true },
{ title: "...", text: "...", isPublished: false }
]
}
```
To bind to the text of the first blog entry, for example, use the _binding expression_ `#blog.entries[0].text`.

## Updating the DOM
Set the text content of an element
```html

{{#blog.entries[0].title}}


{{#blog.entries[0].text}}


```

Hide/show an element
```html


{{#blog.entries[0].text}}

```

Change an image
```html

```

Toggle a CSS class (using jQuery)
```html


  • {{#blog.entries[0].title}}

  • ```

    Call a function
    ```html


    ```

    Say you want to repeat an element a number of times
    ```html

    {{#blog.entries[#i].text}}

    ```

    Set the value of an text box
    ```html

    ```

    Et cetera.

    The `bind-statement` specifies a JavaScript statement that should be executed every time your data changes. It is one of just 6 _binding directives_ that together let you write responsive apps of any complexity. They're no less capable than Angular or React.

    Proceed to the [documentation](https://github.com/ken107/databind-js/wiki/Home) for the full list of binding directives.

    ## Example
    http://jsfiddle.net/wcoczs50/4/