Esempio n. 1
0
        public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null,
                                               string valueUpdate = null, bool renderEvenInServerRenderingMode = false, bool setValueBack = false)
        {
            var expression = control.GetValueBinding(property);

            if (expression != null && (!control.RenderOnServer || renderEvenInServerRenderingMode))
            {
                writer.AddAttribute("data-bind", name + ": " + expression.GetKnockoutBindingExpression(), true, ", ");
                if (valueUpdate != null)
                {
                    writer.AddAttribute("data-bind", "valueUpdate: '" + valueUpdate + "'", true, ", ");
                }
            }
            else
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                if (setValueBack && expression != null)
                {
                    control.SetValue(property, expression.Evaluate(control, property));
                }
            }
        }
Esempio n. 2
0
        public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                nullBindingAction();
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression()
                });
            }
        }
Esempio n. 3
0
 public virtual void Add(string name, DotvvmControl control, DotvvmProperty property, Action? nullBindingAction = null)
 {
     var binding = control.GetValueBinding(property);
     if (binding == null)
     {
         if (nullBindingAction != null) nullBindingAction();
         else Add(name, JsonConvert.SerializeObject(control.GetValue(property), DefaultViewModelSerializer.CreateDefaultSettings()));
     }
     else
     {
         entries.Add(new KnockoutBindingInfo(name, GetKnockoutBindingExpression(control, binding)));
     }
 }
        public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                else
                {
                    Add(name, JsonConvert.SerializeObject(control.GetValue(property)));
                }
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression(control)
                });
            }
        }
Esempio n. 5
0
 public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property)
 {
     writer.WriteUnencodedText($"<!-- ko { name }: { control.GetValueBinding(property).GetKnockoutBindingExpression() } -->");
 }