json实现前后台的相互传值详解(2)


 var DataClass = {
     create: function () {
                 return function () {
                     this.MyInit.apply(this, arguments);//创建对象的构造函数  //arguments 参数集合  系统名称 不能写错
                 }
             }
 }
 var MyDataPack = DataClass.create();
 MyDataPack.prototype = {
     //初始化
     MyInit: function (url, operation, params) {
                 this.data = new Object();   //所有数据容量
                 var bdata = new Object();
                 bdata.url = url;            //地址
                 bdata.operation = operation;//操作
                 bdata.params = params;      //参数
                 this.data.BasicData = bdata; //基本数据
             },
     //添加数据 如:addValue("obj", "111");
     addValue: function (p, obj) {
         this.data[p] = obj;
     },
     //取得 所有标记控件的值 并写入数据
     getValueSetData: function (togName) {
                 var values = Object(); //值的集合
                 $("[subtag='" + togName + "']").each(function () {
                     //如果是input 类型 控件
                     if (this.localName == "input") {
                         //如果是text 控件
                         if (this.type == "text" || this.type == "hidden") {
                             values[this.id] = this.value;
                         }
                         else if (this.type == "...") {
                         }
                         //......
                     }
                     else if (this.localName == "...") {
                     }
                     //................
                 });
                 this.data[togName] = values;//添加到数据集合
             },
     //取值 如:getValue("BasicData")
     getValue: function (p) {
                 return this.data[p];
             },
     //获取或设置url
     getUrl: function (url) {
                 if (url)
                     this.data.BasicData["url"] = url;
                 else
                     return this.data.BasicData["url"];
             }
     ,
     //取值 转成字符串的对象 数据
     getJsonData: function () {
         return $.toJSONString(this.data);
     }
 }

三、创建绑定前台数据对象 [用来读取后台传过来的值,并绑定到前台页面]

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxgpg.html