js中,这种写法的传参怎么解释,涉及什么知识点?

发布于 2022-09-05 22:06:55 字数 919 浏览 23 评论 0

在看ztree树的demo中,看到这样的传参方式

$("#addLeaf").bind("click", {isParent:false}, add);

 var newCount = 1;
    function add(e) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        isParent = e.data.isParent,
        nodes = zTree.getSelectedNodes(),
        treeNode = nodes[0];
        console.log(e.data.vip);
        if (treeNode) {
            treeNode = zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, isParent:isParent, name:"new node" + (newCount++)});
        } else {
            treeNode = zTree.addNodes(null, {id:(100 + newCount), pId:0, isParent:isParent, name:"new node" + (newCount++)});
        }
        if (treeNode) {
            zTree.editName(treeNode[0]);
        } else {
            alert("叶子节点被锁定,无法增加子节点");
        }
    };
        

在第一行代码中,给add函数传入了isParent:false ,而在add行数中,使用e.data.isParent来获取传过来的参数,请问这种写法涉及的知识点事什么?以前没有看到过这样的传参方式。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这种情况翻翻文档就知道了。

.bind( eventType [, eventData ], handler )

第二个参数是eventData
说明如下:

eventData
Type: Anything
An object containing data that will be passed to the event handler.

文档上应该说的很清楚了。

伊面 2022-09-12 22:06:55

这个是jq的bind的传参吧。第二个可选参数传递到最后一个运行函数中,作为事件参数event对象的data字段的值传入。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文