1

I'm new to Lightswitch so please bear with me if this is a stupid, or obvious question. This question is about the Lightswitch HTML client - not the desktop client.

I have the scenario where I have an article that can be tagged against one or more destinations (countries). Ideally, when adding or editing an article, there are multiple tabs. One for details (title, standfirst, body etc.) and another one for tagging. Normally I'd implement this using a checkboxlist.

Any ideas on how would I implement this scenario in Lightswitch would be much appreciated.

Many thanks

4

1 回答 1

3

希望能帮助到你:

Boolean 数据类型的默认控件类型是 FlipSwitch 控件,但您可以使用自定义控件轻松替换 CheckBox。

在屏幕设计器中,选择布尔字段的节点,并将控件类型从 FlipSwitch 更改为自定义控件。在“属性”窗口的“高度”部分中,选择“最小值”并输入 100。这是必要的,因为 CheckBox 控件比标准的 TextBox 控件高。如果您的表单使用其他控件类型,您可能需要调整此值。在 General 部分中,选择 Edit Render Code 链接。在代码编辑器中,将以下代码添加到渲染方法:JavaScript

// Create the checkbox and add it to the DOM.
    var checkbox = $("<input type='checkbox'/>")
            .css({
                height: 20,
                width: 20,
                margin: "10px"
            })
            .appendTo($(element));

    // Determine if the change was initiated by the user.
    var changingValue = false;

    checkbox.change(function () {
        changingValue = true;
        contentItem.value = checkbox[0].checked;
        changingValue = false;
    });
    contentItem.dataBind("value", function (newValue) {
        if (!changingValue) {
            checkbox[0].checked = newValue;
        }
    });

如果您在添加/编辑屏幕上显示必填字段的复选框,您还需要为控件设置初始值,否则用户可能会收到验证错误。要设置初始值,请在实体设计器的透视栏上,选择 HTMLClient 选项卡。在编写代码列表中,选择已创建。在代码编辑器中,通过将代码添加到创建的方法来设置初始值:JavaScript entity.FieldName = new Boolean(); entity.FieldName = 'true'; 将 FieldName 替换为您的布尔字段的名称。要将控件初始化为未选中状态,请将 true 替换为 false。

于 2014-07-01T15:47:54.370 回答