请教一个关于 jsgrid 小问题

2017-10-27 09:31:06 +08:00
 slysly759

问题描述

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.

1388 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/401107

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX