如何使用 JSON 在 jquery 控件中设置类型函数的属性



我有一个jquery datepicker控件。我想使用它创建一个自定义 ASP.net 控件。JQuery 日期选择器在 Show 之前有一个属性。此属性的类型为函数。在 ASP.Net cotrol 中,我尝试使用 JSonItem 的字符串类型设置函数,如下所示:

StringBuilder strFunction = new StringBuilder();
            strFunction.AppendLine(@"function (input) { ");
            strFunction.AppendLine(@" setTimeout(function () { ");
            strFunction.Append(@" var buttonPane = $(""#" + ClientID);
            strFunction.Append(@""")");
            strFunction.AppendLine(@".datepicker(""widget"").find("".ui-datepicker-close"").click(function () {");
            strFunction.Append(@" $.datepicker.clearDate($(""#" + ClientID );
            strFunction.AppendLine(@"""));");
            strFunction.AppendLine(@" });");
            strFunction.AppendLine(@" }, 1);");
            strFunction.AppendLine("}"); 
textInput.Call("datepicker", Js.Json(
                Js.JsonItem("onSelect", Js.Function(delegate {
                    if (ValueSelected != null) {
                        var request = CreateMethodInvocationRequest("OnSelect");
                        request.Send();
                    }
                })
            ),
//This is the function type of property
Js.JsonItem("beforeShow",strFunction.ToString())

));

在这里,但我没有得到结果。运行时 JScript 错误被抛出。如果我之前没有设置显示属性,那么一切正常。但我需要这个属性。谁能提出其他方法?

根据需要使用下面的一个,而不是在显示之前,

呈现渲染前,后渲染

我们不能在 beforeShow 之前使用,因为它只有在与 show 方法一起使用时才会被触发。

我使用一个函数解决了这个问题,该函数返回将字符串解析为 JSExpression。

Js.JsonItem("beforeShow",strFunction.ToString())

最新更新