localStorage不刷新网格

时间:2013-01-16 10:45:41

标签: jquery grid local-storage kendo-ui

我无法解决这个问题。

这是我的代码

var selectedID = "";
    var selectedIDPremise = "";
    var PremisesGrid = "";
    var PremisesGrid2 = "";
    var selectedIDPremise2 = "";
    //var selectedOD2 = "";
    var nova = "";

    $(document).ready(function () {



        $("#routes").kendoDropDownList({
            dataTextField: "Name",
            dataValueField: "Id",
            dataSource: {
                type: "application/jsonp",
                transport: {
                    read: {
                        url: "http://" + servername + "/uBillingServices/Administration/Administration.svc/getRoute",
                        dataType: "json",
                        data: {
                            ID: 0
                        }
                    }
                }
            },
            select: onSelect
        });

        //nova = PremisesGrid2.getKendoDropDownList().dataSource.transport.options.read.data.Route_ID;

        function onSelect(e) {

            //$.getJSON("http://" + servername + "/uBillingServices/Administration/Administration.svc/getRoute", { ID: nova }, function (json) { });
            window.localStorage.setItem("Nova", "");
            nova = this.dataItem(e.item.index());
            window.localStorage.setItem("Nova", nova.ID);
            PremisesGrid2.getKendoGrid().dataSource.read();
            //nova = PremisesGrid2.getKendoDropDownList().dataSource.transport.options.read.data.Route_ID;
            // var data = [{}];
            //PremisesGrid2.getKendoGrid().dataSource.data(data)
            for (var i = 0; i < 3000; i++) {
                if (i == 2999) {
                    PremisesGrid2.getKendoGrid().dataSource.read();
                }
            }

        }
            PremisesGrid2 = $("#assignedRoute").kendoGrid({
                //dataTextField: "Name",
                //dataValueField: "Id",
                dataSource: {
                    type: "application/jsonp",
                    transport: {
                        read:
                                {
                                    url: "http://" + servername + "/uBillingServices/Premise/Premise.svc/GetAllPremisesByRoute",
                                    dataType: "json",
                                    data: {
                                        Route_ID: window.localStorage.getItem("Nova"),
                                        UserName: userName,
                                        WorkStation: workStation

                                    }
                                }
                    },
                    schema: {
                        model: {
                            fields: {
                                ID: { type: "string" },
                                PostalCode: { type: "string" },
                                Latitude: { type: "string" },
                                Longitude: { type: "string" },
                                IsMember: { type: "string" }

                            }
                        }
                    }
                },
                change: function (arg) {

                    myIndex = this.select().index();
                    var PremisesRow = this.select();

                },
                dataBound: function (e) {

                    row = e.sender.tbody.find(">tr:not(.k-grouping-row)").eq(0);
                    if (row.length == 0) {
                        e.sender.select(e.sender.tbody.find(">tr:first"));
                    }
                    else {
                        e.sender.select(row);
                    }
                },
                selectable: true,
                scrollable: true,
                filterable: true,
                groupable: false,
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
                height: 330,

                columns: [
                    { field: "PostalCode", title: "Assigned Route" }
                    ]//, width: "100px"
            });

localStorage工作正常(在它更改的资源中),但是当我选择另一个Reon(从DropDown列表中)时它不刷新网格,当我刷新页面时它显示我选择的最后一个

谁能告诉我这是什么问题?感谢

1 个答案:

答案 0 :(得分:1)

有几个问题:

  1. IDId之间的混淆。
  2. {li> data transport.read.data中的定义需要是一个函数。

    关于1.在DropDownList定义中,您说dataValueField: "Id",但在onSelect中,您使用:window.localStorage.setItem("Nova", nova.ID);

    关于2.将data的定义从object更改为function。这样:

    data    : function () {
        return {
            {
                Route_ID: window.localStorage.getItem("Nova"),
                UserName: userName,
                WorkStation: workStation
            }
        }
    }