Hello I'm using knockout foreach to generate my layout. I have problems with settings attributes in proper way. Here is my code:
<div class="row" data-bind="foreach: points">
<div class="col-md-4" id="oferty" data-bind="event: { mouseenter: $parent.mouseEnter, mouseout: $parent.mouseOut}">
<h2 data-bind="text: name"></h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p>
<a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a>
</p>
</div>
</div>
I need to populate in some way attribute data-name with my points -> name data. To get something like here:
<div class="col-md-4" data-name="Test1" id="oferty">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p>
</div>
<div class="col-md-4" data-name="Test2" id="oferty">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p>
</div>
I tried:
addAttributes: {'data-name': name}
and
attr: {'data-name': name}
But none of them works. Can someone suggest my simple solution of my problem?
Update1 Answer for the nemesv No errors in the console.
var poszukiwane = $(this).attr("data-name");
console.log(poszukiwane);
Above code always returns undefined...
Update2: adding Jsfiddle:
But don't know how to include more than 1 js framework there so will throw error in one line
<div class="col-md-4" id="oferty" data-bind="event: { mouseenter: $parent.mouseEnter, mouseout: $parent.mouseOut}, attr: { 'data-name': name }">- nemesv