4

我正在创建一个带有关联客户端 API 的 ASP.NET 服务器控件。

在我的 GetScriptDescriptors() 方法中,我关联了一个名为“rows”的属性......

descriptor.AddProperty("rows", this.IntRows);

在我的客户端 API 中,我希望我的“行”属性是只读的......

MyControl = function(element)
{
    MyControl.initializeBase(this, [element]);
    this._rows;
}

MyControl.prototype =
{
    initialize: function()
    {
        MyControl.callBaseMethod(this, 'initialize');
    },

    get_rows: function()
    {
        return this._rows;
    },

    dispose: function()
    {
        MyControl.callBaseMethod(this, 'dispose');
    }
}

但是,这会导致以下错误...

错误:Sys.InvalidOperationException:'rows' 不是可写属性。

为了让 $create 语句为“rows”分配它的初始值,似乎需要以下设置器:

set_rows: function(value)
{
    this._rows = value;
},

如果需要设置器从 AddProperty 调用中分配值,如何在客户端 API 中将“行”属性设置为只读?

4

1 回答 1

0

Simplest method would be to have the set_rows ignore any input. Effectively this should stop the Exception from occurring altogether and still provide Read Only functionality to the property.

set_rows: function(value)
{
    value = null;
},
于 2011-01-20T15:27:53.140 回答