Is it possible to add static text to data-bind with something like the example below:
<p data-bind="text:someProperty"></p>
I would like to add static text as below:
<p data-bind="text:' + $' + someProperty"></p>
I'm quite late, (and new to Knockout) but here is another option I have used to add static text around an observable. In my case I wanted to add parentheses around a value that was chosen from a drop-down.
javascript
...
return function AppViewModel() {
this.myOptionValues = ko.observableArray([
{ label: "Foo", value: "Bar" },
]);
this.mySelectedValue = ko.observable();
this.myValue = ko.computed(function () {
return this.mySelectedValue() ? '(' + this.mySelectedValue().label + ')' : '';
}, this);
};
...
html
<small data-bind="text: myValue"></small> // (Foo)
Can you not put the static text inside the paragraph tag along with a span tag and data-bind on the span?
<p>text: <span data-bind="[whatever]" /></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With