淘汰赛 - HTML href [英] knockout - HTML href

查看:196
本文介绍了淘汰赛 - HTML href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遍历数组的foreach循环(filesObservableArray)。该数组的键/值包含键:URLPath。当我在HTML中绑定数组时,我想用URLPath设置'href ='值。

I have a foreach loop that goes through an array (filesObservableArray). The array has a key/value with the key: URLPath. When I bind the array within the HTML, I would like to set the 'href=' value with the URLPath.

我知道这部分是失败的,但从概念上讲,你能看到我想做的事吗?

I know this part is a fail, but conceptually, can you see what I'm trying to do?

href =< span data-bind ='text:URLPath'>

或者我可以使用'databind =click:someCode(url)'并在someCode函数中打开链接? URL映射到文档文件(例如,.doc)或图像文件。

Or maybe I can use a 'databind="click: someCode(url)"' and within the someCode function, open the link? The url maps to either a document file (e.g., .doc) or an image file.

提示赞赏。谢谢!

<tbody data-bind="foreach: $root.filesObservableArray">
                    <tr id="tradeRow">
                        <td><a href="<span data-bind='text: URLPath'></span>">Open file</a></td>
                    </tr>
                </tbody>


推荐答案

我不确定你想要实现什么? href中的跨度,但 attr 绑定你可以设置 href (或任何其他)属性:

I am not sure what do you want to achive with the span in the href but with the attr binding you can set just fine the href (or any other) attribute:

<tbody data-bind="foreach: $root.filesObservableArray">
   <tr id="tradeRow">
       <td><a data-bind="attr: { href: URLPath }">Open file</a></td>
   </tr>
</tbody>

这篇关于淘汰赛 - HTML href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆