剑道UI下拉菜单张贴阵列 [英] Kendo UI drop downs posting arrays

查看:263
本文介绍了剑道UI下拉菜单张贴阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用剑道UI的ListView使用模板,怎么每次当表单提交和数据发布的所有dropdownlists张贴作为数组

林。在此先感谢!

我的继承人下拉列表中的模板

 <输入名称=id_proof_clt数据绑定=值:id_proof_clt数据值场=value_opt数据文本字段=label_opt数据选项-label =选择数据源=dsIdProof数据角色=DropDownList的/>

继承人的阵列其职位

  id_proof_clt ['id_opt']
id_proof_clt ['category_opt']
id_proof_clt ['label_opt']
id_proof_clt ['value_opt']

现在这些都是我的数据库表中的字段。我只希望它张贴value_opt。我的继承人的数据源。

  VAR dsIdProof =新kendo.data.DataSource({
    运输: {
        阅读:{
          网址:/数据/选项/
          数据类型:JSONP
      },
      parameterMap的:功能(选择,操作){
          如果(操作===读){
              返回选项;
          }
      }
    },
    serverFiltering:真实,
    过滤:[{
        现场:category_opt
        经营者:情商
        值:id_proof
    }]
 });

它返回的JSON是:

<$p$p><$c$c>jQuery1910549811847275123_1415223627371([{\"id_opt\":150,\"category_opt\":\"id_proof\",\"value_opt\":\"Driving许可证,label_opt:驾驶执照},{id_opt:151,category_opt:id_proof,value_opt:护照,label_opt:护照}])

现在我的继承人交通运输,模型,数据源和ListView:

  / ***********************
    客户端传输
  *********************** /
  VAR clientTransport = {
      阅读:{
          网址:/数据/客户/
          数据类型:JSONP
      },
      创建: {
          网址:/数据/客户/制造,
          键入:POST,
          数据类型:JSONP
          完成:功能(E){
            如果(的document.getElementById('gridClients')){
                $(#gridClients)数据(kendoGrid)dataSource.read()。;
            }
          }
      },
      更新:{
          网址:/数据/客户/更新,
          键入:POST,
          数据类型:JSONP
          完成:功能(E){
            如果(的document.getElementById('gridClients')){
                $(#gridClients)数据(kendoGrid)dataSource.read()。;
            }
          }
      },
      毁灭:{
          网址:/数据/客户机/破坏,
          键入:POST,
          数据类型:JSONP
      },
      parameterMap的:功能(选择,操作){
          如果(操作!==读){
              options.dob_clt = kendo.toString(options.dob_clt,YYYY-MM-DD);
              options.dob_2_clt = kendo.toString(options.dob_2_clt,YYYY-MM-DD);              //如果外键被EMPTY设置为NULL
              如果(options.sales_advisor_clt ==''){
                   options.sales_advisor_clt ='空';
              }
              如果(options.case_manager_clt ==''){
                   options.case_manager_clt ='空';
              }
              如果(options.chaser_clt ==''){
                   options.chaser_clt ='空';
              }
          }
           返回选项;
      }
  }  / ***********************
    客户端模式
  *********************** /
  VAR clientModel = kendo.data.Model.define({
      ID:id_clt
      字段:{
          id_clt:{编辑:假},
          title_clt:{编辑:真正},
          fname_clt:{编辑:真正},
          mname_clt:{编辑:真正},
          lname_clt:{编辑:真正},
          lmname_clt:{编辑:真正},
          dob_clt:{类型:日期,设置defaultValue:空},
          address1_clt:{编辑:真正},
          address2_clt:{编辑:真正},
          city​​_clt:{编辑:真正},
          county_clt:{编辑:真正},
          后code_clt:{编辑:真正},
          previous_address1_clt:{编辑:真正},
          previous_address2_clt:{编辑:真正},
          previous_city_clt:{编辑:真正},
          previous_county_clt:{编辑:真正},
          previous_post code_clt:{编辑:真正},
          telephone_clt:{编辑:真正},
          mobile_clt:{编辑:真正},
          email_clt:{编辑:真正},
          title_2_clt:{编辑:真正},
          fname_2_clt:{编辑:真正},
          mname_2_clt:{编辑:真正},
          lname_2_clt:{编辑:真正},
          lmname_2_clt:{编辑:真正},
          dob_2_clt:{类型:日期,设置defaultValue:空},
          mobile_2_clt:{编辑:真正},
          email_2_clt:{编辑:真正},
          id_proof_clt:{编辑:真正},
          sales_advisor_clt:{设置defaultValue:'空'},
          case_manager_clt:{设置defaultValue:'空'},
          lead_ref_clt:{编辑:真正},
          chaser_clt:{设置defaultValue:'空'},
          //自定义
          声明:{编辑:假},
          status_clt:{编辑:假},
          sales_advisor:{编辑:假},
          //日志
          创建:{编辑:假},
          更新:{编辑:假},
          用户:{编辑:假}
      }
  });  / ***********************
    客户数据
  *********************** /
  VAR clientData =新kendo.data.DataSource({
      交通:clientTransport,
      错误:功能(E){
          如果(e.responseText){
              警报(e.responseText);
          }
      },
      模式:{
          解析:功能(响应){
             $。每个(响应函数(IDX,ELEM){
                 如果(elem.dob_clt&安培;&安培; typeof运算elem.dob_clt ==字符串){
                     elem.dob_clt = kendo.parseDate(elem.dob_clt,YYYY-MM-DD);
                 }
                 如果(elem.dob_2_clt&安培;&安培; typeof运算elem.dob_2_clt ==字符串){
                     elem.dob_2_clt = kendo.parseDate(elem.dob_2_clt,YYYY-MM-DD);
                 }
             });
             返回响应
          },
          数据:数据,
          总:总,
          型号:clientModel
      },
      serverPaging:真实,
      每页:?&LT; PHP的echo $ pageSize的; ?&gt;中
      页:??&LT; PHP回声$页面;&gt;中
      serverFiltering:真实,
      过滤器:
      &LT;?如果PHP($ _ GET ['id_clt']){&GT;
          {场:id_clt,经营者:情商,值:?&LT; PHP的echo $ _GET ['id_clt'];&gt;中},
      &LT; PHP}; ?&GT;
      &LT;?如果PHP($ _ GET ['状态']){&GT;
          {场:status_clt,经营者:&LT; PHP的echo($ _ GET ['经营者'] =!?$ _GET ['经营者']:包含?);&gt;中,值:&LT ; PHP的echo $ _GET ['地位'];?&gt;中},
      &LT; PHP}; ?&GT;
      &LT; PHP如果($模式==仪表板){&GT?;
          {场:sales_advisor_clt,经营者:情商,值:&LT; PHP的echo $用户ID&GT;? },
      &LT; PHP}; ?&GT;
      ]
      serverSorting:真实,
       排序:[{场:创造,导演:递减},{场:更新,导演:递减}],
  });/ ***********************
    客户端窗体
  *********************** /
  如果(的document.getElementById(formClient)){
      变种clientListView = $(#formClient)。kendoListView({
          数据源:clientData,
          模板:kendo.template($(#viewTemplate)HTML()。)
          editTemplate:kendo.template($(#formTemplate)HTML()),
          数据绑定:功能(E){
             // this.edit(this.element.children()第());
          },
          变化:功能(E){
              //this.edit(this.element.children()第());
          }
      })的数据(kendoListView);
  }


解决方案

您的下拉列表中的值绑定到一个数组 id_proof_clt ,因为你明确告诉它通过使用数据绑定=值:id_proof_clt。相反,你应该使用数据绑定=来源:id_proof_clt绑定其源,而不是价值。

Im using a Kendo UI listView with a template, how every when the form is submitted and the data is posted all dropdownlists are posted as an array. Thanks in advance!!!

Heres my drop down lists in the template

<input name="id_proof_clt" data-bind="value:id_proof_clt" data-value-field="value_opt" data-text-field="label_opt" data-option-label="Select" data-source="dsIdProof" data-role="dropdownlist" />

heres the array it posts

id_proof_clt['id_opt']
id_proof_clt['category_opt']
id_proof_clt['label_opt']
id_proof_clt['value_opt']

Now these are the fields in my DB table. I only want it to post the 'value_opt'. Heres my datasource.

 var dsIdProof = new kendo.data.DataSource({
    transport: {
        read: {
          url: "/data/options/",
          dataType: "jsonp"
      },
      parameterMap: function(options, operation) {
          if (operation === "read") {
              return options;
          }
      }
    },
    serverFiltering: true,
    filter: [{
        field: "category_opt",
        operator: "eq",
        value: "id_proof"
    }]
 });

The json it returns is:

jQuery1910549811847275123_1415223627371([{"id_opt":150,"category_opt":"id_proof","value_opt":"Driving Licence","label_opt":"Driving Licence"},{"id_opt":151,"category_opt":"id_proof","value_opt":"Passport","label_opt":"Passport"}])

Now heres my Transport, Model, Datasource and listView:

/***********************
    CLIENT TRANSPORT
  ***********************/
  var clientTransport = {
      read: {
          url: "/data/clients/",
          dataType: "jsonp"
      },
      create: {
          url: "/data/clients/create",
          type: "POST",
          dataType: "jsonp",
          complete: function(e) {
            if (document.getElementById('gridClients')) {
                $("#gridClients").data("kendoGrid").dataSource.read();
            } 
          } 
      },
      update: {
          url: "/data/clients/update",
          type: "POST",
          dataType: "jsonp",
          complete: function(e) {
            if (document.getElementById('gridClients')) {
                $("#gridClients").data("kendoGrid").dataSource.read();
            } 
          }
      },
      destroy: {
          url: "/data/clients/destroy",
          type: "POST",
          dataType: "jsonp"
      },
      parameterMap: function(options, operation) {
          if (operation !== "read") { 
              options.dob_clt = kendo.toString(options.dob_clt,"yyyy-MM-dd");
              options.dob_2_clt = kendo.toString(options.dob_2_clt,"yyyy-MM-dd");

              //IF FOREIGN KEYS ARE EMPTY SET TO NULL
              if(options.sales_advisor_clt == ''){
                   options.sales_advisor_clt = 'null';
              }
              if(options.case_manager_clt == ''){
                   options.case_manager_clt = 'null';
              }
              if(options.chaser_clt == ''){
                   options.chaser_clt = 'null';
              }
          }
           return options;
      }
  }

  /***********************
    CLIENT MODEL
  ***********************/
  var clientModel = kendo.data.Model.define( {
      id: "id_clt",
      fields: {
          id_clt:               { editable: false },
          title_clt:            { editable: true },
          fname_clt:            { editable: true },
          mname_clt:            { editable: true },
          lname_clt:            { editable: true },
          lmname_clt:           { editable: true },
          dob_clt:              { type: "date", defaultValue: null },
          address1_clt:         { editable: true },
          address2_clt:         { editable: true },
          city_clt:             { editable: true },
          county_clt:           { editable: true },
          postcode_clt:         { editable: true },
          previous_address1_clt:{ editable: true },
          previous_address2_clt:{ editable: true },
          previous_city_clt:    { editable: true },
          previous_county_clt:  { editable: true },
          previous_postcode_clt:{ editable: true },
          telephone_clt:        { editable: true },
          mobile_clt:           { editable: true },
          email_clt:            { editable: true },
          title_2_clt:          { editable: true },
          fname_2_clt:          { editable: true },
          mname_2_clt:          { editable: true },
          lname_2_clt:          { editable: true },
          lmname_2_clt:         { editable: true },
          dob_2_clt:            { type: "date", defaultValue: null},
          mobile_2_clt:         { editable: true },
          email_2_clt:          { editable: true },
          id_proof_clt:         { editable: true },
          sales_advisor_clt:    { defaultValue: 'null' },
          case_manager_clt:     { defaultValue: 'null' },
          lead_ref_clt:         { editable: true },
          chaser_clt:           { defaultValue: 'null' },
          //Custom
          claims:               { editable: false },
          status_clt:           { editable: false },
          sales_advisor:        { editable: false },
          //Log
          created:              { editable: false },
          updated:              { editable: false },
          user:                 { editable: false }
      }
  });

  /***********************
    CLIENT DATA
  ***********************/
  var clientData = new kendo.data.DataSource({
      transport: clientTransport,
      error: function(e) {
          if(e.responseText){
              alert(e.responseText);
          }
      },
      schema: {
          parse: function(response) {
             $.each(response,function(idx,elem) {
                 if(elem.dob_clt && typeof elem.dob_clt=="string") {
                     elem.dob_clt = kendo.parseDate(elem.dob_clt,"yyyy-MM-dd");
                 }
                 if(elem.dob_2_clt && typeof elem.dob_2_clt=="string") {
                     elem.dob_2_clt = kendo.parseDate(elem.dob_2_clt,"yyyy-MM-dd");
                 }
             });
             return response
          },
          data: "data",
          total: "total",
          model: clientModel
      },
      serverPaging: true,
      pageSize: <?PHP echo $pageSize; ?>,
      page: <?PHP echo $page;?>,
      serverFiltering: true,
      filter: [
      <?PHP if($_GET['id_clt']){ ?>
          { field: "id_clt", operator: "eq", value: "<?PHP echo $_GET['id_clt'];?>" },
      <?PHP }; ?>
      <?PHP if($_GET['status']){ ?>
          { field: "status_clt", operator: "<?PHP echo ($_GET['operator'] != "" ? $_GET['operator'] : "contains");?>", value: "<?PHP echo $_GET['status'];?>" },
      <?PHP }; ?>
      <?PHP if($mode == "dashboard"){ ?>
          { field: "sales_advisor_clt", operator: "eq", value: "<?PHP echo $userID ?>" },
      <?PHP }; ?>
      ],
      serverSorting: true,
       sort: [{ field: "created", dir: "desc" }, { field: "updated", dir: "desc" }],
  });

/***********************
    CLIENT FORM
  ***********************/
  if (document.getElementById("formClient")) {
      var clientListView = $("#formClient").kendoListView({
          dataSource: clientData,
          template: kendo.template($("#viewTemplate").html()),
          editTemplate: kendo.template($("#formTemplate").html()),
          dataBound: function(e) {
             // this.edit(this.element.children().first());
          },
          change: function(e) {
              //this.edit(this.element.children().first());
          }
      }).data("kendoListView");
  }

解决方案

You are binding the value of the dropdown list to an array id_proof_clt because you explicitly told it to by using data-bind="value: id_proof_clt". Instead, you should bind its source, not the value, by using data-bind="source: id_proof_clt".

这篇关于剑道UI下拉菜单张贴阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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