最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - knockout concatenate issue - Stack Overflow

programmeradmin1浏览0评论

I am trying to the following but it's not working:

<!-- ko foreach: _Poi_Images_List -->
  <img data-bind='attr: {alt: "images/"+ PATH }'  />
<!-- /ko -->  

when I remove the "images/"+ part it works, but as soon as I add it. it messes up with javascript and not the actual PATH i want, and it bees like this:

<span data-bind="attr: {alt: "images/"+ PATH }" alt="images/Poi/function c(){if(0&lt;arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}"></span>

any ideas? I have already checked this reference for the concatenation part and I basically did the same: Concatenate Strings in Knockout

thanks

I am trying to the following but it's not working:

<!-- ko foreach: _Poi_Images_List -->
  <img data-bind='attr: {alt: "images/"+ PATH }'  />
<!-- /ko -->  

when I remove the "images/"+ part it works, but as soon as I add it. it messes up with javascript and not the actual PATH i want, and it bees like this:

<span data-bind="attr: {alt: "images/"+ PATH }" alt="images/Poi/function c(){if(0&lt;arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}"></span>

any ideas? I have already checked this reference for the concatenation part and I basically did the same: Concatenate Strings in Knockout

thanks

Share Improve this question edited May 23, 2017 at 12:23 CommunityBot 11 silver badge asked Nov 21, 2012 at 15:59 roy naufalroy naufal 3991 gold badge8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You have to unwrap observable when use it in expression. Change your code to this:

<!-- ko foreach: _Poi_Images_List -->
  <img data-bind='attr: {alt: "images/"+ PATH() }'  />
<!-- /ko -->
发布评论

评论列表(0)

  1. 暂无评论