[试图在MVC中绑定列时为什么在列中查看[object Object]

问题描述 投票:0回答:1

这是我在准备好文档时在索引中调用的JS

jsonfields = @Html.Raw(Json.Encode(ViewBag.ColumnData));

这是我绑定的Ajax调用

function onTeamTreeLoad(e) {
    try {
        $.ajax({
            type: "POST",
            url: window.ApplicationPath + 'Generic/GetTeamTree',
            dataType: "json",
            headers: { "__RequestVerificationToken": $("#AntiForgeryToken").val() },
            contentType: 'application/json',
            success: function (data) {
                if (data != null) {
                    $("#TeamName").kendoDropDownTree({
                        dataSource: {
                            schema: {
                                model: {
                                    children: "Items"
                                }
                            },
                            data: data
                        },
                        dataTextField:  "Text",
                        dataValueField: "Id"
                    });

                    try {
                        if (e.model.TeamName !== "") {
                            $("#TeamName").data("kendoDropDownTree").text(e.model.TeamName);
                        }
                    } catch (e) { }
                }
            },
            error: function () {
                console.log('Failed to load');
            }
        });
    } catch (e) {
        console.log(e);
    }
}

为什么在尝试绑定列时看到[objectObject]?我希望查看数据而不是objectObject。我尝试将SerializeObject方法添加到ID和Text,但是在编辑时无法查看该列!我想知道AJAX调用中是否有任何错误,如果使用SerializeObject或JSON.Stringify,需要添加哪些内容。

javascript ajax combobox asp.net-ajax kendo-asp.net-mvc
1个回答
0
投票

这里您只是打印对象。所以Object-> Stringify给出类似[object Object]的输出。

您可以尝试使用此代码。

for(var prop in obj) {
  console.log(obj[prop]);
}
© www.soinside.com 2019 - 2024. All rights reserved.