有没有人知道是否可以让DynaTree jquery插件为每个节点处理两个HREF链接?
我有一个链接工作正常但我也在查看在每个可点击节点的右侧显示“联系人”图像的请求,当点击时产生一个弹出窗口(我知道,不是我的设计)处理同一项目的其他用户。
我可以使用SPAN标签相当容易地显示图像,但由于现有的HREF是OnActivate捕获的HREF,因此我无法做任何事情。
欢迎所有建议。
答案 0 :(得分:2)
我发现了一种更好的方法。
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: {
type: "POST",
url: "TreeView/GetNodes"
// This gets data from an MVC3 controller
// in the form of a serialised list of nodes
// with custom attributes.
},
//here's the meat of it -
// elements are created and added
// according to the custom data values in the node
onRender: function (node, nodeSpan) {
if (node.data.hasPostImage) {
var postImg = document.createElement('img');
postImg.setAttribute('src', node.data.postImageUrl);
postImg.setAttribute('class', node.data.postImageClass);
postImg.setAttribute('alt', node.data.postImageAltText);
postImg.setAttribute('onClick', 'javascript:loadContacts(\'' + node.data.postImageScriptHref + '\');');
// the element is then appended to the Anchor tag (title)
// using jquery.after.
// it works really well, except for IE7. Working on that now.
$(nodeSpan).find('.dynatree-title').after(postImg);
}
},
onClick: function (node) {
node.toggleExpand();
}
});
});
</script>
答案 1 :(得分:0)
我注意到直接输出树允许我在结构中嵌入图像标记,如下所示 -
<div id="tree">
<ul id="treeData" style="display: none;">
@foreach (var provider in Model.Locations)
{
<li class="folder" data="icon: 'false', addClass: 'root-node'">@provider.Provider
<ul>
@foreach (var profession in provider.ChildLocations)
{
<li id="@profession.Id">@profession.Profession <img class="contactsImg" onclick="loadContacts();" src="../../Content/themes/default/images/icons/contacts.png" />
<ul>
@foreach (var formtype in profession.ChildLocations)
{
<li class="folder" id="@formtype.Id" data="addClass: 'progress-bar'">@formtype.Type
<ul>
@foreach (var form in formtype.ChildLocations)
{
<li id="@form.Id" data="addClass: 'progress-bar'">@Ajax.ActionLink(form.Form, "PartialIndex", "FormCover", new { Id = form.formId }, new AjaxOptions { UpdateTargetId = "contentpanel" })
<ul>
@foreach (var lo in form.ChildLocations)
{
<li id="@lo.Id" data="addClass: 'action-required'">@Ajax.ActionLink(lo.Name, "ActualFormTab", new {formid = form.formId, layoutid = lo.formId}, new AjaxOptions{ UpdateTargetId = "contentpanel"})</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</div>
而且,正如所展示的那样,向图像添加OnClick事件非常简单。