javascript - Knockout JS Json get -
i newbie @ knockout.js
, have question. found code here. function returns {"id":"1", "name":"cardio", "image":"aslas", "header":"kardio", "message":"message\r\n"}
not working. can me?
<ul class="folders" data-bind="foreach: folders"> <li data-bind="text: $data, css: { selected: $data == $root.chosenfolderid() }, click: $root.gotofolder"></li> </ul> <div class="mails" data-bind="with: chosenfolderdata"> <p><label>from</label>: <span data-bind="text: name"></span></p> </div> <script> function webmailviewmodel() { // data var self = this; self.folders = ['cardio', 'classic', 'mass', 'abs'] ; self.chosenfolderid = ko.observable(); self.chosenfolderdata = ko.observable(); self.chosenmaildata = ko.observable(); // behaviours self.gotofolder = function(folder) { self.chosenfolderid(folder); self.chosenmaildata(null); $.get(ajax_url+'dieticians/video/'+folder,null, self.chosenfolderdata); }; self.gotofolder('inbox'); }; ko.applybindings(new webmailviewmodel()); </script>
is looking for?: http://jsfiddle.net/58tkrbd9/3/
<ul class="folders" data-bind="foreach: folders"> <li data-bind="text: $data, css: { selected: $data == $root.chosenfolderid() }, click: $root.gotofolder"></li> </ul> <br> <div class="mails" data-bind="with: chosenfolderdata"> <p><label>from</label>: <span data-bind="text: name"></span></p> </div> <script type="text/javascript"> function webmailviewmodel() { var self = this; self.folders = ko.observablearray(['cardio', 'classic', 'mass', 'abs']); self.chosenfolderid = ko.observable(); self.chosenfolderdata = ko.observable(); self.chosenmaildata = ko.observable(); // behaviours self.gotofolder = function(folder) { console.log(folder); self.chosenfolderid(folder); self.chosenmaildata(null); //apply ajax call , fill 'chosenfolderdata' self.chosenfolderdata({"id":"1", "name":"cardio", "image":"aslas", "header":"kardio", "message":"message\r\n"}); }; self.gotofolder('inbox'); }; ko.applybindings(new webmailviewmodel()); </script>
Comments
Post a Comment