【问题标题】:Fetch server side data using typescript使用打字稿获取服务器端数据
【发布时间】:2018-01-26 10:32:36
【问题描述】:

我是打字稿的新手,我想知道如何在打字稿中编写以下代码。我的项目在 asp.net MVC 中。 这是我的代码

    $("#EmployeeCode").autocomplete({
        source: function (request, response) {
           $("#EmployeeCode").val('');
           $.ajax({
           url: '/Admin/Search/Country/' + request.term,
           dataType: "json",
           type: "GET",
           contentType: "application/json; charset=utf-8",
           success: function (data) {
            response($.map(data, function (item) {
                return {
                    label: item,
                    val: item.split('-')[1],
                }
            }))
        },
        error: function (response) {
            console.log(response.responseText);
        },
        failure: function (response) {
            console.log(response.responseText);
        }
    });
},
select: function (e, i) {
    // $(this).val(i.item.val);
    $("#EmployeeCode").val(i.item.val);
},
minLength: 3

});

【问题讨论】:

  • 嗯,根据您设置的打字稿规则,有效的打字稿。如果您有需要类型的规则,则需要添加类型定义文件。如果您没有类型定义文件,您可以创建它们或作弊,然后到处乱扔:any

标签: javascript c# typescript asp.net-mvc-4 typescript2.0


【解决方案1】:

Typescript 只是 javascript 的超集,因此 javascript 是有效的。如果您想按原样使用它,您可以使用它。

【讨论】:

    猜你喜欢
    • 2019-10-16
    • 2016-05-24
    • 1970-01-01
    • 2020-02-03
    • 2011-03-02
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多