knockout.js - asp.net mvc spa durandaljs date format not working with Knockout -


i'm exploring durandaljs asp.net mvc spa. i'm using aps.net mvc4, durandaljs, knockoutjs, breeze, moment , other libs found under hottowel spa sample.

i have client view bound dob, datetime.

    <td colspan="2">                     <span id="dob" data-bind="text: dob"></span>             </td>                                                 

and viewmodel contains code

    vm.studentprofile().dob(moment(vm.studentprofile().dob()).format('l'));         logger.log(vm.studentprofile().dob(), null, system.getmoduleid(vm), false); 

above code comes querysucceeded. i.e

    return manager         .executequery(query)         .then(querysucceeded)         .fail(queryfailed); 

this supposed working i've achieved other fields in case of datetime knockoutout doesn't update gui whereas can see updated format date in console log. can tell me missing here. in advance.

the problem may lie fact dob momentjs date, not javascript date or string. need add custom binding handler displaying these dates, such example:

ko.bindinghandlers.moment = {             update: function(element, valueaccessor) {                 var value = valueaccessor();                 var formattedvalue = ko.utils.unwrapobservable(value).format('llll');                 $(element).text(formattedvalue);             } }; 

now, instead of using "text" binding handler, use "moment" binding handler this:

<span id="dob" data-bind="moment: dob"></span> 

edit: added example of adding custom plugins using amd modules requirejs:

require(['jquery', 'json2', 'sammy', 'amplify', 'bootstrap', 'moment', 'toastr', 'showdown', 'markdowneditor', 'spin'],          function($){          // require plugins loaded, after prerequisite libraries         //       load plugins here , don't have          //       name them in modules use them because         //       don't want modules know use plugins.         requirejs([                 'jquery.ui',                // jquery plugin                 'jquery.mockjson',          // jquery plugin                 'jquery.tmpl',          // jquery plugin             ],              function () {                  require(['ko'],                     function(ko) {                         // ensure ko in global namespace ('this')                          if (!this.ko) {                             this.ko = ko;                         };                          requirejs([                                 'libs/knockout.binding.handlers',       // knockout custom binding handlers                                 'libs/knockout.extenders',       // knockout custom binding handlers                                 'libs/bootstrap.extenders',       // knockout custom binding handlers                             ],                             // plugins don't return module objects                             // there point in passing parameters function                             function () {                                  require(['app'], function(app) {                                     app.initialize();                                  });                             }                         );                     }                 );             }         );     } ); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -