Kendo UI下载发布数组

时间:2014-11-05 21:51:30

标签: listview kendo-ui kendo-grid

我使用带有模板的Kendo UI listView,每次提交表单和发布数据时,所有下拉列表都作为数组发布。在此先感谢!!!

下面是我在模板中的下拉列表

<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" />

继承人发布的数组

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

现在这些是我的数据库表中的字段。我只希望它发布&#39; value_opt&#39;。继承我的数据源。

 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"
    }]
 });

它返回的json是:

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"}])

现在继承我的传输,模型,数据源和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");
  }

1 个答案:

答案 0 :(得分:0)

您将下拉列表的值绑定到数组id_proof_clt,因为您已使用data-bind="value: id_proof_clt"明确告知它。相反,您应该使用data-bind="source: id_proof_clt"来绑定其来源,而不是值。