WinJS.Binding.as function

1 out of 4 rated this helpful - Rate this topic

Returns an observable object. This may be an observable proxy for the specified object, an existing proxy, or the specified object itself if it directly supports observation.

Syntax


var object = WinJS.Binding.as(data);

Parameters

data

Type: object

The object to observe.

Return value

Type: Object

The observable object.

Remarks

For more information about using this method, see the Programmatic Binding sample at Windows Store app samples.

Examples

The following code shows how to use the as function. Clicking the button causes the binding source to change; since the source is bound to the span, the content of the span changes when the binding source changes.


<div id="nameDiv">
    Welcome, <span id="nameSpan" data-win-bind="textContent: name"></span>
</div> 
<button id="nameButton"></button>   
<script type="text/javascript">
    var person = { name: "Fran" };
    var nameElement = document.getElementById("nameDiv");
    WinJS.Binding.processAll(nameElement, person);
    var bindingSource = WinJS.Binding.as(person);

    var button = document.getElementById("nameButton");

    button.onclick = function (ev) {
       if (bindingSource.name == "Fran") {
           bindingSource.name = "Bob";
       }
       else {
           bindingSource.name = "Fran";
       }
    };
</script>

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Namespace

WinJS.Binding

Library

Base.js

 

 

Build date: 12/5/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.