1

此代码在快照中返回以下结果。

单击模板而不是单击模板时,如何使用 FirstName 和 LastName 填充文本字段[object object]

function forAutoComplete(FieldName){
        var autoCompleteUsers = $("#employees").kendoAutoComplete({
            minLength: 1,
            dataTextField: FieldName,

            template: '<div style="border-bottom: 1px solid DARKGRAY; padding:10px 0; clear:both;">' +
                      '<img  style="float:left; margin-right:20px;" width=\"127\" height=\"127\" src=\"<?php echo base_url() ?>/user_uploads/employee_images/${data.Photo}\" alt=\"${data.Photo}\"/>'+
                      '<div style="display: inline-block;"><p>${ data.FileNo}</p>' +
                      '<h3>${ data.FirstName } ${ data.LastName }</h3></div>'+
                      '<div style="clear: both; "></div></div>',

            dataSource: {
                serverFiltering: true,
                transport: {
                    read: {
                        type: "GET",
                        dataType: "json",
                        contentType:'application/json; charset=utf-8',
                        url: "<?php echo base_url() ?>index.php/hr_management/manage_hr/search_employee/",
                        data: function (arg){
                            return {FieldName : autoCompleteUsers.data("kendoAutoComplete").value()};
                        }
                    }
                }
            },
            height: 300,
            change: onChangeAutoComplete
        });
    }

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

4

该问题可能与您设置的值有关dataTextField

进行某种逆向工程,我猜您返回的 JSON 数据类似于:

[
    {data: { FileNo: "0001", FirstName: "OnaBai", LastName: "it's me", Photo: "https://si0.twimg.com/profile_images/2648375258/7f7e451f0de1eb467fe35f4f481d7bf7_bigger.jpeg" } },
    {data: { FileNo: "0002", FirstName: "Burke", LastName: "Holland", Photo: "https://si0.twimg.com/profile_images/3342899483/51e933d69222ce8ad8cd14e655116959.jpeg" } },
    {data: { FileNo: "0003", FirstName: "Todd", LastName: "Anglin", Photo: "https://si0.twimg.com/profile_images/1478082886/todd-anglin-close-up_illustrated.png" } }
]

如果是这样,您应该将其定义为data.FirstName.

如果您将其定义为:

[
    { FileNo: "0001", FirstName: "OnaBai", LastName: "it's me", Photo: "https://si0.twimg.com/profile_images/2648375258/7f7e451f0de1eb467fe35f4f481d7bf7_bigger.jpeg" },
    { FileNo: "0002", FirstName: "Burke", LastName: "Holland", Photo: "https://si0.twimg.com/profile_images/3342899483/51e933d69222ce8ad8cd14e655116959.jpeg" },
    { FileNo: "0003", FirstName: "Todd", LastName: "Anglin", Photo: "https://si0.twimg.com/profile_images/1478082886/todd-anglin-close-up_illustrated.png" }
]

那么它应该只是FirstName

第一种方法的示例在这里,而第二种方法在这里

如果您dataTextField: "data",为 JSON 定义并使用第一种方法,那么您将获得[object Object]. 看这里

于 2013-04-19T18:09:03.663 回答