here is the code:
HTML:
<textarea data-bind="value: MyText">
Hello world
line 2
line 3
</textarea>
JS:
var viewModel =
{
MyText : ko.observable()
};
ko.applyBindings(viewModel);
Textarea becomes empty, because of ko.observable(), but how can I save existing value in textarea?
I have big multiline document in textarea (from database), and I want to edit it with features of Knockoutjs.
Thanks.
Don’t extract the text from HTML, just make your view model like this:
http://jsfiddle.net/HSfuq/1/
I would prefer the first method.
Or you can extract the text from the html like this, if you must do so:
HTML:
JS:
http://jsfiddle.net/HSfuq/2/
Or use JSON serialization (any way you like,
return JSON(yourDataIncludingMultiLineText);from MVC controller action, or a serializer library like Newtonsoft JSON.net http://nuget.org/List/Packages/Newtonsoft.Json) to serialize the multi line text.