V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
slysly759
V2EX  ›  问与答

请教一个关于 jsgrid 小问题

  •  
  •   slysly759 · 2017-10-27 09:31:06 +08:00 · 1517 次点击
    这是一个创建于 2603 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题描述

    Uncaught TypeError: $(...).dialog is not a function 但是我在 stack 看了一下,说要加这个 dialog function 但是我在代码中的确是加了这个。

    /**
     * Created by Administrator on 2017/4/13.
     */
    
    $(function () {
        var admin_flag = [
            { Name: "否", Id: 0 },
            { Name: "是", Id: 1 }
        ];
    
        query_user='/api/users';
        $.getJSON(query_user,function (user_data) {
            clients=user_data['data'];
            $("#jsGrid").jsGrid({
                height: "400px",
                width: "100%",
    
                filtering: true,
                editing: true,
                sorting: true,
                paging: true,
                autoload: true,
    
                rowClick: function(args) {
                    showDetailsDialog("Edit", args.item);
                },
                // controller: db,
    
                pageSize: 10,
                pageButtonCount: 5,
    
                deleteConfirm: "真的要删除喵?",
    
    
    
                data: clients,
    
                fields: [
                    { name: "name", type: "text", width: 150, validate: "required"},
                    { name: "email", type: "text", width: 150,validate: "required" },
                    { name: "created_time", type: "text", width: 200 },
                    { name: "admin_flag", type: "select", items: admin_flag, valueField: "Id", textField: "Name" },
                    // { name: "Married", type: "checkbox", title: "Is Married", sorting: false },
                    // { name: "password",type: "text", width: 150, validate: "required"},
                    {
                    type: "control",
                    modeSwitchButton: false,
                    editButton: false,
                    headerTemplate: function() {
                        return $("<button>").attr("type", "button").text("Add")
                                .on("click", function () {
                                    showDetailsDialog("Add", {});
                                });
                    }}
                ]
            });
    
        $("#detailsDialog").dialog({
            autoOpen: false,
            width: 400,
            close: function() {
                $("#detailsForm").validate().resetForm();
                $("#detailsForm").find(".error").removeClass("error");
            }
        });
    
        $("#detailsForm").validate({
            rules: {
                name: "required",
                email: { required: true },
                created_time: { required: true, minlength: 10 },
                admin_flag: "required"
            },
            messages: {
                name: "Please enter name",
                email: "Please enter valid age",
                created_time: "Please enter created_time (more than 10 chars)",
                admin_flag: "Please enter admin_flag"
            },
            submitHandler: function() {
                formSubmitHandler();
            }
        });
    
        var formSubmitHandler = $.noop;
    
        var showDetailsDialog = function(dialogType, client) {
            $("#name").val(client.name);
            $("#email").val(client.email);
            $("#created_time").val(client.created_time);
            $("#admin_flag").val(client.admin_flag);
            // $("#married").prop("checked", client.Married);
    
            formSubmitHandler = function() {
                saveClient(client, dialogType === "Add");
            };
    
            $("#detailsDialog").dialog("option", "title", dialogType + " Client")
                    .dialog("open");
        };
    
        var saveClient = function(client, isNew) {
            $.extend(client, {
                name: $("#name").val(),
                email: parseInt($("#email").val(), 100),
                created_time: $("#created_time").val(),
                admin_flag: parseInt($("#admin_flag").val(), 100)
                // Married: $("#married").is(":checked")
            });
    
            $("#jsGrid").jsGrid(isNew ? "insertItem" : "updateItem", client);
    
            $("#detailsDialog").dialog("close");
        };
        });
    });
    
    
    
    

    后续问题

    1. 因为学 js 比较浅显,想问一下,在一个 js 文件中 为何要加这个匿名自启动的 function 包裹整个 js 呢?
    2. ajax 如何调用外部的函数呢 感觉这次问题就出现在这里。
    3. 感觉每次这样询问都挺耗费时间的,不知道大家有没有什么收费的群,每个月收点钱,然后很快能够答疑的平台或者社群啥的==。

    any help thx in advance.

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2610 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:55 · PVG 22:55 · LAX 06:55 · JFK 09:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.