jquery.tree中selectnode:function的传值问题

js代码:


           function load(){
               $("input").val("");//设定文本框的值
               //autoFill($("#search-keywords"));
                o ={   
                   url: "treeview",//请求ThesMgrAction的treeview方法
                  selectnode: function(id, name, value, parentId){
                       $("#addParentId").val(id),$("#modId").val(id), $("#modName").val(name),$("#modSynonyms").val(value),$("#modParentId").val(parentId), $("#delId").val(id),$("#delParentId").val(parentId)
                   }//获得当前值

                };
                $.ajax({
                   url: o.url,
                   type: "POST",//请求方式
                   async: false,//同步请求
                   data: { //发送到服务器的数据
                       id: 0
                   },
                   success: function(treedata){
                       o.data = treedata;
                   }
                });
               
               $("#tree").treeview(o);//?
               $("#add").click(function(){//添加
                   if ($("#addParentId").val() == "") {
                       openmsgdialog("请先选择一个上级节点");
                   }
                   else {
                       $('#dialogAdd').dialog('open');
                   }
                });
               $("#mod").click(function(){//修改
                   if ($("#modId").val() == "") {
                       openmsgdialog("请选择一个关键词");
                   }
                   else
                       if ($("#modId").val() == 1) {
                           openmsgdialog("顶层节点不能修改");
                       }
                       else {
                           $('#dialogMod').dialog('open');//打开修改对话框
                       }
                });
               $("#del").click(function(){//删除
                   if ($("#delId").val() == "") {
                       openmsgdialog("请选择一个关键词");
                   }
                   else
                       if ($("#delId").val() == 1) {
                           openmsgdialog("顶层节点不能删除");
                       }
                       else {
                           if (confirm("此操作不可恢复,可能导致系统崩溃,您确定删除吗?")) {
                               $.ajax({
                                   url: "treedel",
                                   type: "POST",
                                   data: {
                                       id: $("#delId").val()
                                   },
                                   success: function(msg){
                                       if (msg.result == 1) {
                                           $("#tree").reflash($("#delParentId").val());
                                       }
                                       else {
                                           openmsgdialog(msg.errMsg);
                                       }
                                   },
                                   error: function(msg){
                                       openmsgdialog("发生未知错误");
                                   }
                               });
                           }
                       }
                  
                });
               $("#dialogAdd").dialog('destroy');
               $('#dialogAdd').dialog({//添加的对话框
                   autoOpen: false,
                   width: 200,
                   height: 300,
                   modal: true,
                   buttons: {
                       '取消': function(){
                           $(this).dialog('close');
                       },
                       '新增': function(){
                           var text = $('#addName'), value =$('#addSynonyms'), thesParentId = $('#addParentId')
                           var tips = $("#dialogAdd.validateTipsl");
                           var bValid = true;
                           bValid = bValid && checkNotNull(text,"关键词名不能为空",tips);
                           if (bValid) {
                               $.ajax({
                                   url: "treeadd",
                                   type: "POST",
                                   contentType:"application/x-www-form-urlencoded;charset=UTF-8",
                                   data: {
                                       text: text.val(),
                                       value: value.val(),
                                       thesParentId: thesParentId.val()
                                   },
                                   success: function(msg){
                                      
                                       if (msg.result == 1) {
                                           $("#tree").reflash($("#addParentId").val());
                                           $('#dialogAdd').dialog('close');
                                          
                                       }
                                       else {
                                           updateTips(msg.errMsg, tips);
                                       }
                                      if(msg.fieldErrors!=null){
                                          updateTips(msg.fieldErrors.value, tips);
                                       }

                                      
                                   },
                                   error: function(msg){
                                       updateTips("发生未知异常", tips);
                                   }
                               });
                           }
                       }
                   },
                   close: function(){
                       $('#dialogAdd form')[0].reset();
                       $("#dialogAdd").children().removeClass("ui-state-error");
                       $("#dialogAdd.validateTipsl").text("");
                   }
                })


原理:


id, name, value, parentId字段在action中都能找到与之相匹配的相同变量,action中的变量通过json封装后传递给UI的selectnode:function方法。换句话说,function将调用后台的get方法来得到id, name,value, parentId字段的值


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值