Jamie Hutber
Jamie Hutber

Reputation: 28126

Using knockout to build a dynamic attr

I need to have knockout create the image src for me, but I only have one part of the image location. I am using an items ID as the image names. Works

<img alt="" data-bind="attr: {src: $data.img}">

Needed

  <img alt="" data-bind="attr: {src: /img/clients/$data.img.jpg}">

Upvotes: 1

Views: 501

Answers (1)

mako-taco
mako-taco

Reputation: 732

perhaps try this:

<img alt="" data-bind="attr: {src: '/img/clients/' + $data.img + '.jpg'}">

Upvotes: 3

Related Questions