如果我取消选中并切换回同一幻灯片,如何存储复选框的值



行为:默认情况下将复选框设置为true,因此,即使我在JS中取消选中的复选框,当我从其他幻灯片切换到当前时,复选框值也将其设置为true幻灯片。

期望:如果我取消选中并应存储更新值,则应取消选中复选框,因此,当我再次选择同一幻灯片时,应取消选中复选框。

复选框的JavaScript代码:

    function getSlideShowDetailPropList() {     
     var publish = {
                type: "checkbox",
                id: "Publish",
                displayName: "Active",
                propertyDefinition: {
                    value: angular.isDefined(activePortalComponent) ? activePortalComponent.viewModel.actSlideShow.publish : ""
                }
            };
     return [publish];
   if (id === "Publish") {
 activePortalComponent.viewModel.actSlideShow.publish = value;
     }              
   }       

CSHARP代码,其中复选框的硬编码为true:

    public bool publish { get; set; }
    provider.cs
   private Slideshow CreateSlideshow(int i)
            {
                Slideshow slideshow1 = new Slideshow();
                slideshow1.publish = true;
                return slideshow1;
            }

getProperties.cs用于返回复选框值:

    public IDictionary<string, object> GetSlideshowProperties( Slideshow foundSlideshow, IReadOnlyList<string> propertyNames )
            {
                var result = new Dictionary<string, object>();
                foreach (string propertyName in propertyNames)
                {
                     if (propertyName == "publish")
                    {
                        result.Add(propertyName, foundSlideshow.publish);
                    }
                }
            return result;
        }

存储您从后端获得的布尔值,在组件变量中获得stateChecked,然后将此值绑定到下面的模板中的复选框状态checked

在您的组件中,单击"单击"复选框,当您的页面加载时,将在后端发送true时默认检查复选框,但是在UI上,您可以更改复选框的状态:

updateState() { 
    this.stateChecked = !this.stateChecked
}

最新更新