javascript - 基于单击的按钮隐藏 Kendo 实用程序窗口中的元素

标签 javascript c# jquery

好的,这一切相对较新:我有一个 Kendo Grid,其中的客户 ID 是根据客户、年份以及客户获得帮助的次数自动生成的。要使用不同的地址或服务制作新副本,它会打开一个实用程序窗口,您选择公司,它会生成 Id,然后您填写字段。我还想使用它通过编辑按钮更新客户记录,打开相同的实用程序窗口但隐藏 Pick company 下拉菜单,因为已经创建了 Id。

这是在主页上:

<script>
function closeWindow(e) {
    $(this.element).empty();
}

function editJobs(e) {
    e.preventDefault();
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

    var win = $("#utilityWindow").data("kendoWindow");
    win.refresh({ url: "/BackendSchedule/_Jobs?jobId=" + dataItem.Id});
    win.setOptions({
        title: "Edit Jobs",
        width: 1000,
        height: 600,
    });
    win.center().open();

}

function newJobs() {
    var win = $("#utilityWindow").data("kendoWindow");
    win.refresh({ url: "/BackendSchedule/_Jobs?jobId="});
    win.setOptions ({
        title: "Add New Jobs",
        width: 1000,
        height: 600,
    });
    win.center().open();
}

这是窗口

<form id="JobForm" class="form-horizontal">
    <fieldset class="input">
        <p class="info">

        </p>
        <p id="buildJobId" class="hidden">
            <label for="storeType">Store Type</label>
            @(Html.Kendo().DropDownList()
                .Name("storeType")
                .OptionLabel("please select")
                .BindTo((SelectList)ViewData["jobtypes"])
                .Events(e => e.Change("storeTypeChange"))
                .HtmlAttributes(new { style = "width:275px;" })
            )
        </p>
        <p>
            <label for="Id">Id</label>
            @Html.TextBoxFor(model => model.Id, new { @class = "k-textbox", @readonly = "readonly" })
        </p>
        <p>
             <label for="Company">Company Name</label>
                @(Html.Kendo().DropDownList()
                .Name("Company")
                .OptionLabel("Please Select")
                .BindTo((SelectList)ViewData["company"])
                .HtmlAttributes(new { style = "width:275px;" })
                )
        </p >
        <p>

            <label for="Address1">Address</label>
            @Html.TextBoxFor(model => model.Address1, new { @class = "k-textbox" })<br/> 
            <p> 
                <label for="Address2"></label>
                @Html.TextBoxFor(model => model.Address2, new { @class = "k-textbox" })
            </p>
        </p>
        <p>
            <label for="City">City</label>
            @Html.TextBoxFor(model => model.City, new { @class = "k-textbox" })
        </p>
        <p>
            <label for="State">State</label>
            @(Html.Kendo().DropDownList()
                .Name("State")
                .OptionLabel("Please Select")
                .BindTo((SelectList)ViewData["states"])
                .HtmlAttributes(new { style = "width:200px;" })
            )
        </p>
        <p>
            <label for="ZipCode">Zip Code</label>
            @Html.TextBoxFor(model => model.ZipCode, new { @class = "k-textbox" })
        </p>
        <p>
            <label for="ContactName">Contact Name</label>
            @Html.TextBoxFor(model => model.ContactName, new { @class = "k-textbox"})
        </p>
        <p>
            <label for="Phone">Phone</label>
            @Html.TextBoxFor(model => model.Phone, new { @class = "k-textbox", type = "tel" })
        </p>
        <p>
            <label for="Email">Email</label>
            @Html.TextBoxFor(model => model.Email, new { @class = "k-textbox", required = "required" })
        </p>
        <p>
            <label for="TimeAllowed">Time Allowed</label>
            @(Html.Kendo().NumericTextBoxFor(
        </p>
        <p>
            <label for="PlanStartDate">Plan Start Date</label>
            @(Html.Kendo().DatePickerFor(m => m.PlanStartDate))
        </p>
        <p>
            <label for="PlanEndDate">Plan End Date</label>
            @(Html.Kendo().DatePickerFor(m => m.PlanEndDate))
        </p>
        <p>
            <label for="ReponsibleParty">Responsible Party</label>
            @(Html.Kendo().DropDownList()
                .Name("Contact")
                .OptionLabel("Please Select")
                .BindTo((SelectList)ViewData["responsibleParty"])
                .HtmlAttributes(new { style = "width:300px;" })
            )
        </p>

        <p>
            <button class="k-button" id="submitForm" name="submitForm" type="submit">Submit</button>
            <button class="k-button right" id="cancelButton" type="button">Cancel</button>
        </p>
        <div id="message" class="text-danger"></div>
    </fieldset>
</form>

现在隐藏的 Id=buildJobId 将需要显示在创建新按钮上。

这是我认为可行的代码:

        if ($("#Id").data("TextBoxFor").dataSource.data(null)){
            $("#buildJobId").show();
        } else {
            $("#buildJobId").hide();
        };

最佳答案

添加了一些代码,但在最后一部分让它工作,我将它连接到将要调用的函数:

 $(document).ready(function() {
    var validator = $("#JobForm").kendoValidator().data("kendoValidator");
    var postUrl = "/BackendSchedule/Jobs_Update";

    if ("@ViewBag.Id".length == 0) {
        postUrl = "/BackendSchedule/Jobs_Create";
        $("#buildJobId").show();
    } else {
        $("#buildJobId").hide();
    }

关于javascript - 基于单击的按钮隐藏 Kendo 实用程序窗口中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30484168/

相关文章:

javascript - MongoDB $addtoSet 和 $set 在同一个操作中

javascript - 构造函数对象名称 - javascript

c# - 计算距离工作日的时间

c# - 从 AD 组中获取用户

javascript - 将所有变量合并为一个变量

javascript - 在 Angular 智能表中选择 st-search 不适用于 ng-model

javascript - For Loop on array from dynamic API in JSON format within template literals

c# - 从接口(interface)强制执行可序列化而不强制类在 C# 中自定义序列化

javascript - 不正确的 jQuery 元素宽度计算

Javascript 隐藏在 php 中