javascript - Display raw api data with knockout -
this should simple , although i'm new ko don't seem able result.
i want add function view model call , display api has html text in like:
<p class="class">this text</p>
the view/page should call text using ko , display this:
<span data-bind="text: mytext"></span>
i've been using $.getjson requests inside function. need simplest way this. stackers.
you mean ajax call loads text?
you need set view model, apply bindings, , @ last set result of ajax call.
remember set bind data-bind='html:
document.viewmodel = { mytext: ko.observable() }; ko.applybindingstodescendants(document.viewmodel, document.getelementbyid("content")); //make ajax call , handle result //$.getjson('/some/url', function(data){` //document.viewmodel.mytext(data); document.viewmodel.mytext('<p class="class">this text</p>'); //});
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script> <div id="content"> <span data-bind="html: mytext"></span> </div>
Comments
Post a Comment