javascript - 如何在Javascript中获取模型的属性?

标签 javascript

我想在javascript中获取模型的属性。所以我的 ajax 调用正在从 Controller 接收模型列表。在javascript中,成功后,我想获取模型的特定属性。下面是我的脚本:

$("#filter").keyup(function () {
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: 'Search',
        success:
        function (result) {
            console.log(result.Books);
            var filter = $("#filter").val();
            console.log(filter);
            // Loop through each row of the table
            result.Books.forEach(
                (function (book, index) {
                    console.log(index);
                    var i = index;
                    var title = book[index];
                    // If the list item does not contain the text phrase fade it out
                    if ($(title).text().search(new RegExp(filter, "i")) < 0) {
                        $(book).fadeOut();

                        // Show the list item if the phrase matches and increase the count by 1
                    } else {
                        $(book).show();
                    }
                })
            )
        }

    });
});

正如你所看到的,我已经尝试过 var title=book[index]。我想要这样的东西:

var title = book[index].Title;

其中标题是模型的一个属性(此处为书本)。知道如何做到这一点吗?

最佳答案

只需使用book.Title

bookresult.Books 集合的一个元素,因此您不需要使用 index

关于javascript - 如何在Javascript中获取模型的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434959/

相关文章:

javascript - jQuery idSelector.bind() 方法不能正常工作

javascript - 从 node.js 使用 SharePoint 2013 进行身份验证

JavaScript 案例 : "look at" + item

javascript - 与模式匹配或为空字符串的正则表达式

javascript - 更新状态列表

javascript - 是否可以从工作人员那里调用 SubtleCrypto 方法?

javascript - joi:不返回自定义错误,abortEarly 设置为 false

javascript - 对象反射和枚举 - JavaScript

javascript - jQuery 验证 : hide error messages and change invalid fields background color

javascript - 静态定位的div框问题