Knockout.js, set observable value manually from de

2019-07-29 05:36发布

Giving the following setup:

<textarea id="textarea-chat" type="text" data-bind="value: chatMessage" /> 

I'd like to open the developer console and manually set the value of chatMessage

document.getElementById('textarea-chat').value = 'somevalue';

Will change the content of the of the DOM element, but not the observer value. Accessing chatMessage() results in undefined

Suggestions are welcome

标签: knockout.js
1条回答
劫难
2楼-- · 2019-07-29 06:17

Taking the ideas from here and here, you need to access the value of chatMessage through the ViewModel, which is available in the console when you use the ko.dataFor() method. So, the steps would be:

  1. var vm = ko.dataFor(document.body)
  2. vm.chatMessage('somevalue')
查看更多
登录 后发表回答