Ejemplo n.º 1
0
        /// <summary>
        /// 重新构造.
        /// </summary>
        public override void Recombine( )
        {
            this.ChangeAsync.EventType = EventType.autocompletechange;

            // request.term represents user input, it will passed to the server-side as parameter term
            this.sourceAsync.Data = "{ term: request.term }";

            //!+ The following code is similar with PlusinSetting.Recombine, AjaxManager.Render
            string data;

            if (string.IsNullOrEmpty(this.sourceAsync.MethodName))
            {
                data = "data";
            }
            else
            {
                // According to the .NET version to determine the location of JSON
                if (Environment.Version.Major <= 2 || (Environment.Version.Major == 3 && Environment.Version.Minor == 0))
                {
                    data = "data";
                }
                else
                {
                    data = "data.d";
                }

                this.sourceAsync.Data = string.Format("jQuery.panzer.encodeData({0})", this.sourceAsync.Data);
            }

            // Through method response to set JSON Returned from the server-side to the autocomplete, JSON has the form ['a', 'b'] or [{label: 'a', value: 'a'}, {label: 'b', value: 'b'}]
            this.sourceAsync.Success = "function(data){response(-:data);}".Replace("-:data", data);

            // Generate ajax calling scripts, and used in the Source property
            JQuery ajax = JQueryUI.Create(this.sourceAsync);

            if (null != ajax)
            {
                ajax.EndLine( );

                this.Source = "function(request, response) {" + ajax.Code + "}";
            }

            base.Recombine( );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在 jQuery 中包含的页面元素的某个事件中执行或者直接执行 Ajax 调用.
        /// </summary>
        /// <param name="setting">Ajax 相关设置.</param>
        /// <returns>更新后的 JQueryUI.</returns>
        public JQueryUI Ajax(AjaxSetting setting)
        {
            if (setting.EventType == EventType.none)
            {
                return(this);
            }

            string code;

            if (string.IsNullOrEmpty(setting.ClientFunction))
            {
                JQuery ajax = JQueryUI.Create(setting);

                if (null == ajax)
                {
                    return(this);
                }

                code = "function(e){" + ajax.EndLine( ).Code + "}";
            }
            else
            {
                code = setting.ClientFunction;
            }

            if (setting.EventType == EventType.__init)
            {
                if (this.code != string.Empty)
                {
                    this.EndLine( );
                }

                this.AppendCode(code);
            }
            else
            {
                this.Bind(string.Format("'{0}'", setting.EventType), code);
            }

            return(this);
        }