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

Keno UI dropdown list display more fields and then display

我正在尝试通过 kendo 下拉列表显示 Json 数据。 我已将 Json 数据绑定到名为 accounts 的 java 脚本变量。它有 name,id,code,city,state 属性。

我正在尝试显示所有这些 attributes.But 无法做到这一点。下面是我创建的代码。请帮助我或提供指导。

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

  });
}

您可以使用模板:

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

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

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

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

  });
}