Amit Sharma
Amit Sharma

Reputation: 1088

How to bind data from model to view using knockoutJS

in my application i'm able to get data-collection from model when i'm binding it using knockoutJS that it generate an error on console, i need with data-bind attribute data-class, i'm doing so but not working;

my view binding code as :

<div class="filter-map-content" data-bind="foreach: { data: Services, as: 'service' }">
<input type="checkbox" class="custom-checkbox" data-bind="css: { 'id': service.id, 'data-class': 'GTM_MMCheckbox_' + service.title + '_' + service.id }" data-class=" 'GTM_MMCheckbox_' + service.title + '_' + service.id" />
</div>

i'm able to get data collection when i write it on console , i'm getting data collection as result data-class is not finding in my javascript code but data-collection is available

Upvotes: 0

Views: 125

Answers (1)

moradec
moradec

Reputation: 93

<div class="filter-map-content" data-bind="foreach: { data: Services, as: 'service' }">
<input type="checkbox" class="custom-checkbox" data-bind="attr: { 'id': service.id, 'data-class': 'GTM_MMCheckbox_' + service.title + '_' + service.id }" />
</div>

you have to use the "attr"-binding ;)

...and if your "service.title" or "service.id" is observable you have to write e.g. service.title()

Upvotes: 1

Related Questions