Reputation: 321
How can I add the value of a variable in the href of an a tag? I have this but it just throws /api/gridfs/files/function%20c()%7Bif(0
<a id="editTD" data-bind="attr: { href: '/api/gridfs/files/' + $data.filename}" data-toggle="tooltip" title="Download" data-toggle="modal" data-target="#myModal"><i class="fa fa-download text-navy"></i></a>
Upvotes: 0
Views: 31
Reputation: 136
You must call 'filename' with brackets like $data.filename(). See example
<a id="editTD" data-bind="attr: { href: '/api/gridfs/files/' + $data.filename() }" data-toggle="tooltip" title="Download" data-toggle="modal" data-target="#myModal"><i class="fa fa-download text-navy"></i>CLICK</a>
function ViewModel() {
this.filename = ko.observable("aaa");
}
ko.applyBindings(new ViewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<a id="editTD" data-bind="attr: { href: '/api/gridfs/files/' + $data.filename() }" data-toggle="tooltip" title="Download" data-toggle="modal" data-target="#myModal"><i class="fa fa-download text-navy"></i>CLICK</a>
Upvotes: 1