Reputation: 391
I want to simply bind the textContent of an html element to a data string. What I do to achieve this is:
<span id="currentDate" data-win-bind="textContent:Data.currentDateString"></span>
The code defines a namespace Data with
WinJS.Namespace.define("Data", {
currentDateString: currentDateString,
});
where currentDateString is defined as:
var currentDateString = "Monday";
In the ready function of the page I call WinJS.Binding.processAll();. This sets the content of the HTML to the string. But the HTML does not update on a change of the string. I think I have to trigger some event that the string did change. How would I go about that? Is there an easy way as there is the WinJS.Binding.List for list datasources?
Upvotes: 2
Views: 1101
Reputation: 7292
Your object needs to be observable, which your property-defined-on-a-namespace is not.
Your code needs to change like this:
WinJS.Namespace.define("Data", {
currentDate: WinJS.Binding.as({
asString: currentDateString,
}),
});
Data.currentDate.asString = "Another day!";
When the assignment executes, it will change the value.
There are other helpers for observables, such as WinJS.Binding.define
Upvotes: 4