locked
Undocumented WinJS.Binding.converter changes RRS feed

  • General discussion

  • I think I found an undocumented change in WinJS.Binding.converter(function(something){ ... }).

    In WinJS v2 (Windows 8.1), it will no longer fire if the value something is undefined.

    Here is some code to replicate the problem:
    - Create a new project with the Navigation app template and replace the following code below:

    Insert inside the <section>-tag in home.html:

    <div class="template" data-win-control="WinJS.Binding.Template">
        <div style="height: 300px; width: 300px; background-color: dodgerblue; color: white; padding: 10px;">
            <h1 data-win-bind="textContent: title"></h1>
            <h2 data-win-bind="textContent: subtitle; style.color: subtitle Page.Converters.subtitle"></h2>
        </div>
    
    </div>
    <div class="listview" data-win-control="WinJS.UI.ListView"></div>

    Replace the content of home.js with this:

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            ready: function (element, options) {
                var listView = WinJS.Utilities.query(".listview")[0].winControl,
                    tempalte = WinJS.Utilities.query(".template")[0];
    
                var data = new WinJS.Binding.List([
                    { title: "test 1", subtitle: "sub test 1" },
                    { title: "test 2" },
                    { title: "test 3" },
                    { title: "test 4", subtitle: "sub test 4" }
                ]);
    
                listView.itemDataSource = data.dataSource;
                listView.itemTemplate = tempalte;
                listView.layout = new WinJS.UI.GridLayout();
            }
        });
    
        WinJS.Namespace.define("Page.Converters", {
            subtitle: WinJS.Binding.converter(function (subtitle) {
                if (subtitle)
                    return "black";
                return "red";
            })
        });
    
    })();
    

    When the app is launched with WinJS v1, the two middle items will have two red "undefined" in them.
    When launched with WinJS v2 it will be white.

    Friday, November 8, 2013 1:56 PM