示例#1
0
        public KnockoutTagBuilder <TModel> DropDownList <TItem>(Expression <Func <TModel, IList <TItem> > > options, object htmlAttributes, Expression <Func <TModel, TItem, object> > optionsText)
        {
            var tagBuilder = new KnockoutTagBuilder <TModel>(Context, "select", InstanceNames, Aliases);

            tagBuilder.ApplyAttributes(htmlAttributes);
            if (options != null)
            {
                tagBuilder.Options(Expression.Lambda <Func <TModel, IEnumerable> >(options.Body, options.Parameters));
            }
            if (optionsText != null)
            {
                var data = CreateData();
                var keys = data.Aliases.Keys.ToList();
                if (!string.IsNullOrEmpty(Context.GetInstanceName()))
                {
                    foreach (var key in keys)
                    {
                        data.Aliases[Context.GetInstanceName() + "." + key] = data.Aliases[key];
                        data.Aliases.Remove(key);
                    }
                }
                data.InstanceNames = new[] { Context.GetInstanceName(), "item" };
                tagBuilder.OptionsText("function(item) { return " + KnockoutExpressionConverter.Convert(optionsText, data) + "; }");
            }
            return(tagBuilder);
        }
示例#2
0
        public KnockoutTagBuilder <TModel> DropDownList <TItem>(Expression <Func <TModel, IList <TItem> > > options, object htmlAttributes = null, Expression <Func <TItem, object> > optionsText = null)
        {
            var tagBuilder = new KnockoutTagBuilder <TModel>(Context, "select", InstanceNames, Aliases);

            tagBuilder.ApplyAttributes(htmlAttributes);
            if (options != null)
            {
                tagBuilder.Options(Expression.Lambda <Func <TModel, IEnumerable> >(options.Body, options.Parameters));
            }
            if (optionsText != null)
            {
                var data = new KnockoutExpressionData {
                    InstanceNames = new[] { "item" }
                };
                tagBuilder.OptionsText("function(item) { return " + KnockoutExpressionConverter.Convert(optionsText, data) + "; }");
            }
            return(tagBuilder);
        }
示例#3
0
        public KnockoutTagBuilder <TModel> DropDownList <TItem>(Expression <Func <TModel, IList <TItem> > > options, object htmlAttributes = null, string optionsTextValue = null, string optionsIdValue = null)
        {
            var tagBuilder = new KnockoutTagBuilder <TModel>(Context, "select", InstanceNames, Aliases);

            tagBuilder.ApplyAttributes(htmlAttributes);
            if (options != null)
            {
                tagBuilder.Options(Expression.Lambda <Func <TModel, IEnumerable> >(options.Body, options.Parameters));
            }
            if (!string.IsNullOrEmpty(optionsTextValue))
            {
                tagBuilder.OptionsText(optionsTextValue, true);
            }
            if (!string.IsNullOrEmpty(optionsIdValue))
            {
                tagBuilder.OptionsValue(optionsIdValue, true);
            }
            return(tagBuilder);
        }