0

我试图在我的 jqxGrid 中显示一个下拉列表,其中包含来自 json 源的数据。

我现在的代码是(简化的):

var dropDownListSource =
{
    datatype: "json",
    datafields: [
        { name: 'name' },
        { term_id: 'term_id' }
    ],
    id: 'term_id',
    url: Ajax.ajaxurl,
    mtype: 'POST',
    data: {
       action: 'get_taxonomy_terms'
    }
    };

    var dropdownListAdapter = new $.jqx.dataAdapter(dropDownListSource, { autoBind: true, async: false });



// initialize jqxGrid
    $("#jqxgrid").jqxGrid(
columns:
    [
    { text: 'Category', columntype: 'dropdownlist', datafield: 'category', width: 177,
        initeditor: function (row, cellvalue, editor) {
           editor.jqxDropDownList({ displayMember: 'name', source: dropdownListAdapter });
        }
    }
    ]           
 });

JSON是:

[{"term_id":"17","name":"category name","slug":"nova-kategorie-2","term_group":"0","term_taxonomy_id":"17","taxonomy":"budget-category","description":"","parent":"0","count":"0"}]

此代码显示下拉列表,但我需要显示名称并保存 term_id。

我怎样才能做到这一点?

4

1 回答 1

1

这是您正在寻找的示例!

还有很多其他选择!但这就像你知道下拉列表源或者你可以构建自己的源时的内置

http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/gridkeyvaluescolumnwitharray.htm?arctic

于 2014-12-16T07:17:13.660 回答