Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:10:38+00:00 2026-06-17T23:10:38+00:00

I have an issue where I can’t get to a variable inside a function:

  • 0

I have an issue where I can’t get to a variable inside a function:

EDIT
I forgot to add that I am setting this workerPage.grid = $("#grid").data("kendoGrid"); on the jQuery $(function(){});

I can’t use claimsGird variable inside the save function, I have to referenec it by workerPage.grid. Not the other variables like viewModel work fine. Here is the snippet:

save = function () {
                saif.kendoGridUtils.addModifiedDataItems(
                    viewModel.CompanionClaims.Updated,
                    viewModel.CompanionClaims.Added,
                    $("#grid").data("kendoGrid").dataSource.data()
                );

                $.ajax({
                    url: $("#contentForm").attr("action"),
                    data: JSON.stringify(viewModel),
                    type: "POST",
                    contentType: "application/json"
                }).success(function (data) {
                    //syncs viewModel with changes in model
                    $.extend(viewModel, kendo.observable(data));

                    //rebinds the grid data source
                    claimsGrid.dataSource.data(viewModel.CompanionClaims.Rows);

Here is the full script:

var workerPage = (function () {
        var viewModel = kendo.observable(@Html.Raw(Json.Encode(Model))),
            claimsGrid = null,
            deleteFirm = function (firmModel) {
                firmModel.Name = "";
                firmModel.AttorneyName = "";
                firmModel.Address.Line1 = "";
                firmModel.Address.Line2 = "";
                firmModel.Address.City = "";
                firmModel.Address.State = "OR";
                firmModel.Address.ZipCode = "";
                firmModel.Address.PlusFourCode = "";
                firmModel.PhoneNumber = "";
                firmModel.FaxNumber = "";
                firmModel.ContactName = "";
            },
            bind = function () {
                kendo.bind($("#main-content"), viewModel);
            },
            save = function () {
                saif.kendoGridUtils.addModifiedDataItems(
                    viewModel.CompanionClaims.Updated,
                    viewModel.CompanionClaims.Added,
                    $("#grid").data("kendoGrid").dataSource.data()
                );

                $.ajax({
                    url: $("#contentForm").attr("action"),
                    data: JSON.stringify(viewModel),
                    type: "POST",
                    contentType: "application/json"
                }).success(function (data) {
                    //syncs viewModel with changes in model
                    $.extend(viewModel, kendo.observable(data));

                    //rebinds the grid data source
                    claimsGrid.dataSource.data(viewModel.CompanionClaims.Rows);


                    //rebinds view elements to view model so changes are visible
                    //kendo.bind($("#main-content"), viewModel);
                    bind();

                    // Errors and Warnings
                    var results = messageUtils.parseMessages(
                        viewModel.Messages.Errors,
                        viewModel.Messages.Informationals,
                        viewModel.Messages.Warnings
                    );

                    var errs = $("#errors").html(results.errorMessages);
                    $("#informationals").html(results.informationalMessages);
                    $("#warnings").html(results.warningMessages);

                    $.each(saif.kendoGridUtils.processErrors(viewModel.CompanionClaims.Rows), function (i, message) {
                        errs.html(errs.html() + message + "<br>");
                    });
                    // End Errors and Warnings

                });
            },
            deleteRow = function () {
                var row = claimsGrid.select(),
                    rowDataItem = claimsGrid.dataItem(row),
                    rowIndex = $(row).index(),
                    addedItemIndex = $.inArray(rowDataItem, viewModel.CompanionClaims.Added);

                //add to Deleted if not new
                if (addedItemIndex == -1 && $.inArray(rowDataItem, viewModel.CompanionClaims.Rows) != -1) {
                    viewModel.CompanionClaims.Deleted.push(rowDataItem);
                }

                //remove from Added if exists
                if (addedItemIndex != -1) {
                    viewModel.CompanionClaims.Added.splice(addedItemIndex, 1);
                }

                claimsGrid.removeRow(row);

                //select the next row, eg. if you delete row 2, select the row that took that rows poisition after it was deleted.
                claimsGrid.select(claimsGrid.tbody.find(">tr:eq(" + rowIndex + ")"));
            };

        return {
            bind: bind,
            deleteFirm: deleteFirm,
            deleteRow: deleteRow,
            grid: claimsGrid,
            save: save,
            viewModel: viewModel
        };

    }());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:10:39+00:00Added an answer on June 17, 2026 at 11:10 pm

    The issue is that claimsGrid is never set to anything other than null. And setting workerPage.grid won’t change the value of claimsGrid — it’s not a pointer, just a copy.

    You’ll instead have to use a getter/setter. With newer browsers/engines, that can be done with get and set:

    // ...
    return {
        // ...
        get grid() {
            return claimsGrid;
        },
        set grid(grid) {
            claimsGrid = grid;
        },
        // ...
    };
    

    You can also define grid as a function:

    // ...
    function getOrSetGrid(grid) {
        if (typeof newGrid === 'undefined') {
            return claimsGrid;
        } else {
            claimsGrid = grid;
        }
    }
    
    return {
        // ...,
        grid: getOrSetGrid,
        // ...
    };
    // ...
    
    // rather than: workerPage.grid = ...;
    workerPage.grid(...);
    

    Or split it into getGrid and setGrid functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this issue that I can't seem to get my head around... Basically
Heyy can somebody help me ? i have this issue that still do know
I have a jQuery issue I can't get past: (function ($) { var links
I have an issue in that a Symfony2 form can pass validation but still
I have this exact issue ASP.net can’t update page from event handler and it's
I have an issue that is driving me nuts and hoping someone can help.
Happy New Year SO users! I have an issue that I hope someone can
I have an issue that people can't work with an intranet application that is
I have a issue i can't get it to work now let going to
I have an issue that I can't seem to solve. I am randomly generating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.