Kendo UI下拉列表显示更多字段然后显示

时间:2015-04-17 13:24:20

标签: json kendo-ui

我试图通过kendo下拉列表显示Json数据。 我已将Json数据绑定到名为accounts的java脚本变量。它有名称,ID,代码,城市,州属性。

我试图显示所有这些属性。但是无法做到这一点。下面是我创建的代码。请帮助我或提供指示。

function DisplayAccounts(res) {
  var accounts = [];
  var response = $.parseJSON(res);
  for (var idx = 0; idx < response.length; idx++)
  {
    accounts.push({ 
      'name': response[idx].AccountName,        
      'accountid': response[idx].AccountId, 
      'accountcode': response[idx].AccountCode,
      'city':response[idx].City,
      'state':response[idx].State,
      'ce':response[idx].CE
    });  
  }

  $('#accountSelect').kendoDropDownList({
    dataTextField: "name",+"city"+"sate",
    dataValueField: "accountid",+"accountcode"

    dataSource: accounts

  });
}

2 个答案:

答案 0 :(得分:1)

尝试在推送前组合值,并将它们用作键和值字段。

function DisplayAccounts(res) {
  var accounts = [];
  var response = $.parseJSON(res);
  for (var idx = 0; idx < response.length; idx++)
  {
    accounts.push({ 
      'name' : response[idx].AccountName+' '+response[idx].City+' '+response[idx].State,      
      'accountid': response[idx].AccountId+' '+response[idx].AccountCode 

    });  
  }

  $('#accountSelect').kendoDropDownList({
    dataTextField: "name",
    dataValueField: "accountid"

    dataSource: accounts

  });
}

答案 1 :(得分:0)

您可以使用模板:

$('#accountSelect').kendoDropDownList({
    dataTextField: "name",
    dataValueField: "accountid",
    template: '#: name #, #: city#, #: state#',
    valueTemplate: '#: accountid # == #: accountcode #',
    dataSource: accounts
});

这仅适用于视觉格式。您无法格式化输入值。它只能是来自数据源的单列

相关问题