如何在标签的href中添加变量的值?我有这个但是它只是抛出/ 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>
答案 0 :(得分:1)
您必须使用$ data.filename()之类的括号来调用“文件名”。参见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>