0

我是 stackoverflow 和 ext.net 编程的新手,我想扩展 Ext.Net.Window 并添加新属性,即 Store。下面是我的代码:

C#代码:

public class ExtNetBaseWindowDB : Ext.Net.Window
{
  private Store FDBStore;

  protected override List<Ext.Net.ResourceItem> Resources
  { get {
    List<Ext.Net.ResourceItem> baseList = base.Resources;  
    baseList.Capacity += 1; 
    baseList.Add(new Ext.Net.ClientScriptItem(typeof(ExtNetBaseWindowDB), "Ext.Net_Lib.Scripts.ExtNetBaseWindowDB.js", "/Scripts/ExtNetBaseWindowDB.js"));
    return baseList; }
  }

  protected override void OnInit(EventArgs e)
  { FDBStore = new Store {
      ID = "store__",
      PageSize = 5,
      Model = { 
        new Model {
          ID="model__",
          Fields = {
            new ModelField("Field01", ModelFieldType.String),
            new ModelField("Field02", ModelFieldType.Float)  }
        } 
      }
    };
    base.OnInit(e);
  }

  [Browsable(false)]
  [EditorBrowsable(EditorBrowsableState.Never)]
  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  [XmlIgnore]  
  [JsonIgnore]
  public override ConfigOptionsCollection ConfigOptions
  { get {
      ConfigOptionsCollection list = base.ConfigOptions; 
      list.Add("dbStore", new ConfigOption("dbStore", new SerializationOptions("dbStore",  JsonMode.Object), null, DBStore)); 
      return list;
    }
  }

  public Store DBStore
  { get { return FDBStore; } }
}

Javascript 文件:

ExtNet.ExtNetBaseWindowDB = Ext.extend(Ext.window.Window, {
dbStore: null,
initComponent: function () {
    ExtNet.ExtNetBaseWindowDB.superclass.initComponent.call(this); },
initEvents: function () {
    ExtNet.ExtNetBaseWindowDB.superclass.initEvents.call(this); },  
onRender: function (ct, position) {
    ExtNet.ExtNetBaseWindowDB.superclass.onRender.call(this, ct, position); }
});

来自服务器的响应:

Ext.net.ResourceMgr.init({
    id: "ResourceManager1",
    aspForm: "form1",
    icons: ["PageSave", "Cancel"]
});

Ext.onReady(function () {
    Ext.create("Ext.window.Window", {
        hidden: false,
        renderTo: Ext.get("form1"),
        width: 200
});
Ext.create("ExtNet.ExtNetBaseWindowDB", {
    id: "wnd__",
    itemId: "item__",
    height: 300,
    hidden: false,
    renderTo: Ext.getBody(),
    width: 300,
    layout: "form",        
    title: "ExtNetBaseWindowDB",
    dbStore: new Ext.data.Store({
        model: ,
        storeId: "store_ExtNetBaseWindowDB",
        autoLoad: true,
        pageSize: 5,
        proxy: {
            type: 'memory'
        }
    })
});

请帮助我,我的窗口不显示,我的代码有问题吗?(如果我的英语不好,我很抱歉)

4

1 回答 1

0

商店不能以这种方式正确反序列化。

我可以建议以下解决方案。

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    public class ExtNetBaseWindowDB : Ext.Net.Window
    {
        private Store FDBStore;

        public Store DBStore
        {
            get
            {
                return FDBStore;
            }
        }

        public string DBStoreProxy
        {
            get
            {
                if (this.DBStore == null)
                {
                    return "";
                }

                return this.DBStore.ToConfig();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            FDBStore = new Store
            {
                ID = "Store1",
                PageSize = 5,
                Model = 
                { 
                    new Model 
                    {
                        ID = "Model1",
                        Fields = 
                        {
                            new ModelField("Field01", ModelFieldType.String),
                            new ModelField("Field02", ModelFieldType.Float)  
                        }
                    } 
                  }
            };

            base.OnInit(e);
        }

        public override ConfigOptionsCollection ConfigOptions
        {
            get
            {
                ConfigOptionsCollection list = base.ConfigOptions;
                list.Add("dbStore", new ConfigOption("dbStore", new SerializationOptions("dbStore", JsonMode.Raw), null, this.DBStoreProxy));
                return list;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            this.Form.Controls.Add(new ExtNetBaseWindowDB());
        }
    }
</script>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    </form>
</body>
</html>
于 2013-08-16T05:39:21.063 回答