更新时间:2023-12-06 13:55:52
您可以创建一个元素,比如用一个id的div
You could create an element, say a div with an id
<div id='external-json' data-bind='jsonHandler : {}' style='display:none'></div>
然后从您的WinForms中的应用程序。
Then write json to this div from within your winforms app..
var myJson = "{test : 1}";
this.browser.Document.Body.GetElementById("external-json").innerText = myJson;
您甚至可以创建自定义的淘汰赛结合对此有何反应
You could even create a knockout custom binding to react to this
ko.bindingHandlers.jsonHandler = {
update: function(element, valueAccessor) {
//do something with the json
var json = element.innerText;
var obj = eval(json); //hmm
alert(obj.test);
}
};
这显然是一个简单的例子,你可能可以改善的想法很多,你可能需要消息队列,可能调用您的客户端脚本函数,而不是使用的元素。
This is obviously a simple example and you could probably improve the idea a lot, you may need a queue of messages, possibly calling a function in your client script instead of using the element.