Innovative Thinker
Innovative Thinker

Reputation: 1795

adding attribute using knockout js with dynamic string value

I am working on dynamically creating the tiles like UI for showing the metrics. i want to show some color dynamically based on the id. i need to append "_flag" with the dynamic value(symptom.symId = S1). my code is given below.

<div data-bind="foreach: {data:symptomArray , as: 'symptom'}">
<div data-bind="attr:{ id : symptom.symId}"> </div> 
</div>

Please help me

Upvotes: 0

Views: 715

Answers (1)

RP Niemeyer
RP Niemeyer

Reputation: 114792

If I understand your question correctly, then you want to do:

attr: { id: sympton.symId + '_flag' }

or if symId is observable, then:

attr: { id: sympton.symId() + '_flag' }

Upvotes: 1

Related Questions