How to bind a base64 string to image URL in knockout JS

2,922 views
Skip to first unread message

s.saty...@gmail.com

unread,
Mar 23, 2012, 11:59:15 PM3/23/12
to knock...@googlegroups.com
Hi, i would like to bind a base64 string in my model to a image, is it possible in knockout JS, pardon me if that was a dumb question..

rpn

unread,
Mar 24, 2012, 12:20:06 AM3/24/12
to knock...@googlegroups.com
Here is a sample that shows binding a base64 image to the background style of an element or to the src of an image:   http://jsfiddle.net/rniemeyer/zgPMR/ 

<div data-bind="style: { background: 'url(data:image/png;base64,' + selectedValue() + ')'}"></div>

<img alt="" data-bind="attr: { src: 'data:image/png;base64,' + selectedValue() }" /> 

s.saty...@gmail.com

unread,
Mar 24, 2012, 12:27:43 AM3/24/12
to knock...@googlegroups.com
Works like a charm thanks a lot thanks a ton....

chris kerley

unread,
Aug 23, 2018, 6:55:40 PM8/23/18
to KnockoutJS
Thanks man!
Reply all
Reply to author
Forward
0 new messages