Re: [KnockoutJS] Decoding Text data in knockout.js

274 views
Skip to first unread message

Patrick Steele

unread,
Dec 21, 2015, 8:16:43 AM12/21/15
to knock...@googlegroups.com
So the data is already URI encoded?  If so, you'll need to write a custom binding handler to decode the data before displaying it.  Here's a quick-and-dirty example that should get you started.  It grabs the value of the viremodel item bound (your URI-encoded data), decrypts it and then sends it to knockouts "text" binding to use it as normal:

ko.bindingHandlers.decode = {
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
  var value = valueAccessor();
      var data = ko.unwrap(value);
      ko.bindingHandlers.text.update(element, function() { return decodeURIComponent(data); }, allBindings, viewModel, bindingContext);
}
};

Instead of "text" binding, use this one (decode).  Example:

<div data-bind="decode: myURI"></div>




On Mon, Dec 21, 2015 at 7:01 AM, Nidheesh N <n.nidh...@gmail.com> wrote:
Hi all ,
Am new to Knockout .
In my ASP.net MVC4 project i want to display data in a table using API.Am getting the data but one of the variable contains URL that is not decoded Table Data
I want to decode that particular element .http://my.jetscreenshot.com/11825/20151221-mv3v-70kb



How to do the same?Any help
(Sorry for my bad English)

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nidheesh N

unread,
Dec 21, 2015, 11:58:13 PM12/21/15
to KnockoutJS
Thank You Patrik .Its working...Amazing ...Thanks a lot man
Can i ask you something how can i get a documentation for getting these features.After a several googling and all i didnt get a clean documentation for decoding the url data or custom binding ?

Patrick Steele

unread,
Dec 22, 2015, 8:35:21 AM12/22/15
to knock...@googlegroups.com
The knockout website is a great source of information:


I refer to it all the time (and even copy/pasted the binding handler set up code I responded with from the docs).

Nidheesh N

unread,
Dec 23, 2015, 12:19:02 AM12/23/15
to KnockoutJS
Okay Thank You Patrick ....


On Monday, 21 December 2015 18:46:43 UTC+5:30, Patrick Steele wrote:
Reply all
Reply to author
Forward
0 new messages