【问题标题】:How can I bind Autocomplete to a dialog within Serene Template如何将自动完成绑定到 Serene 模板中的对话框
【发布时间】:2016-10-26 04:26:27
【问题描述】:

如果您访问此在线示例模板并查看我在说什么: Serene Template Samples

当您单击“新客户”时,jquery 模态对话框将通过 typescript 创建。在您单击按钮之前,不会在父页面中创建此对话框 div 和表单。

我需要一种将 jquery 对话框中的自动完成功能绑定到其中一个字段的方法,但我无法让它工作。我可以将它绑定到主页上,但由于对话框直到稍后才创建,所以在创建此对话框时如何绑定它?

【问题讨论】:

    标签: jquery jquery-ui modal-dialog jquery-ui-dialog jquery-ui-autocomplete


    【解决方案1】:

    所以我设法糊弄过去,不熟悉打字稿和宁静的模板。我在 xxxxxDialog.ts 文件的构造函数中添加了整个自动完成调用,它似乎运行良好。

        constructor() {
            super();
            $('[name=EmpNum]').autocomplete({
                minLength: 6,
                autoFocus: true,
                source: function (request, response) {
                    $.ajax({
                        url: "/services/adlookup/autocompleteuserlookup",  
    
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term },
                        success: function (data) {
                            response($.map(data, function (item) {//data needs to be array of objects
                                return { label: item.LastName + ", " + item.FirstName + " (" + item.Descriptions + ")", value: item.EmpNum + "|" + item.UserName + "|" + item.LastName + "|" + item.FirstName + "|" + item.EmailAddress + "|" + item.WorkPhone };//item is each item in array item.LastName
                            }))
                        }
                    })
                },
                focus: function () {
                    $(".ui-helper-hidden-accessible").hide();  
                    event.preventDefault();
                    return false;
                }
            })
            .on('autocompleteselect', function (e, ui) { //fill in data after it had been selected
                    var t = $(this),      
                    label = (e.type == 'autocompleteresponse' ? ui.content[0].label : ui.item.label),
                    value = (e.type == 'autocompleteresponse' ? ui.content[0].value : ui.item.value);
                    var adprop = value.split("|");
                    return false;
                });
        }//end constructor
    

    【讨论】:

    • 不错,不过我更愿意将它包装成一个简单的小部件。指南中有一个示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多