Reputation: 311
I have a ko observable variable declared within a view model
selectedResource: {
func: ko.observable
},
This variable is being accessed within the javascript. This code is working fine and displays the variable values within the brower log
loadResourceMethodsAction: function(resource){
console.log("Load Methods Action");
this.bindings.selectedResource(resource);
console.log(this.bindings.selectedResource().displayName());
console.log(this.bindings.selectedResource().description());
console.log(this.bindings.selectedResource().relativeUri());
}
However when I try to read the same variable my DUST template. it fails to read it.
<p>TODO Methods</p>
<p>Selected Resource:</p>
<p>Display Name:<span data-bind="text: selectedResource.displayName"></span></p>
<p>Description :<span data-bind="text: selectedResource.description"></span></p>
<p>Relative URI:<span data-bind="text: selectedResource.relativeUri"></span></p>
I tried attaching () to both selectedResource and displayName but it still doesn't work.
Upvotes: 1
Views: 468
Reputation: 83356
I think you forgot to call it.
func: ko.observable
sets func to the actual ko.observable function; it doesn't call the function to actually create a knockout observable property.
Just change it to
func: ko.observable()
or
func: ko.observable(<default value>)
That said, are you sure you don't want the following?
selectedResource: ko.observable()
Upvotes: 2