行为:在后台代码中,复选框默认设置为true,因此,即使我在JS中取消选中复选框,当我从其他幻灯片切换到当前幻灯片时,复选框值也会设置为true。
期望:如果我取消选中复选框,应该取消选中它,并且应该存储更新的值,所以当我再次选择同一张幻灯片时,应该取消选中该复选框。
checkbox的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;
}
} checkbox硬编码为true的Csharp代码:
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;
}发布于 2017-09-07 14:49:50
将从后端获得的布尔值存储在组件变量stateChecked中,然后将该值绑定到模板中的复选框状态checked,如下所示。
在你的组件中,在点击时切换复选框,这样当你的页面加载时,复选框将被默认选中,因为后端发送true,但是在UI上,你可以改变复选框的状态:
updateState() {
this.stateChecked = !this.stateChecked
}https://stackoverflow.com/questions/46089058
复制相似问题