【问题标题】:Lightswitch HTML Client - set modal picker value when screen createdLightswitch HTML 客户端 - 创建屏幕时设置模式选择器值
【发布时间】:2015-04-16 21:54:19
【问题描述】:

我现在对此进行了大量研究,但没有任何示例有用或适用。我想要做的是当用户加载添加屏幕时,我希望详细信息选择器在创建屏幕时显示一个名称,而不是每次都选择它。我确定这可以做到,但我的 javascript 技能欠缺。

感谢您的帮助, 下面是一个例子:

此名称存储在一个表中,可以在此模式选择器/详细信息选择器中搜索,但您可以想象,如果 50% 的时间需要此值,则手动添加它不仅耗时,而且会变成有点乏味

在每个项目上按post render 后,可以使用contentItem.valueelement.innerText 操作文本框,但这不适用于此类控件,并且出现以下错误:

这里有一些有用的信息可能会有所帮助:

  • ProjectData(数据源)
  • 主屏幕参考 OrderRequest
  • 外键链接引用ShippingContact,并在 DetailsPicker 上搜索 CustomerName

根据以下答案,我是否需要将任何内容替换为顶级函数,然后将代码的第二部分替换为基础,您在其中编写了 defaultLookup(screen.Customer, "Contact", "Contacts", 此处需要做什么?

我试图改变的例子,不幸的是这不起作用

var defaultValue = "Test User";
    var filter = "(ContactName eq " + msls._toODataString(defaultValue, ":String") + ")";
    defaultLookup(screen.OrderRequest, "ContactName", "ShippingContacts", { filter: filter });

【问题讨论】:

    标签: javascript visual-studio-lightswitch lightswitch-2013


    【解决方案1】:

    我们已经实现了以下帮助函数:-

    function defaultLookup (entity, destinationPropertyName, sourceCollectionName, options) {
        /// <summary>
        /// Defaults an entity's lookup property
        /// </summary>
        /// <param name="entity" type="Object">The entity featuring the lookup property to default</param>
        /// <param name="destinationPropertyName" type="String">The lookup property against the entity to default</param>
        /// <param name="sourceCollectionName" type="String">The collection from which to source the lookup value</param>
        /// <param name="options" type="PlainObject" optional="true">
        /// A set of key/value pairs used to select additional configuration options. All options are optional.
        /// <br/>- String filter: If supplied, defines the match condition for the required default, otherwise the lookup defaults to the first entry in the source collection
        /// </param>
        options = options || {}; // Force options to be an object
        var source = myapp.activeDataWorkspace.ApplicationData[sourceCollectionName]; // DataServiceQuery
        var query = {}; //DataServiceQuery
        if (options.filter) {
            query = source.filter(options.filter);
        } else {
            query = source.top(1);
        }
        query.execute().then(function (result) {
            entity[destinationPropertyName] = result.results[0];
        });
    };
    

    在您的情况下,您需要更改 ApplicationData 以读取 ProjectData。

    这可以在屏幕的 created 事件中调用如下:-

    myapp.AddEditCustomer.created = function (screen) {
        var defaultValue = "Chris Cook";
        var filter = "(Name eq " + msls._toODataString(defaultValue, ":String") + ")";
        defaultLookup(screen.Customer, "Contact", "Contacts", { filter: filter });
    };
    

    在您的情况下,screen.Customer 应更改为 screen.OrderRequest,“Contact”应更改为“CustomerName”,“Contacts”应更改为“ShippingContacts”。此外,根据您的查找表有一个名为 ContactName 的字段,过滤器字符串需要引用 ContactName 而不仅仅是名称。

    或者,可以从您的实体创建的事件(在您的 UserCode 脚本部分中)调用此帮助程序,如下所示:-

    myapp.Customer.created = function (entity) {
        var defaultValue = "Chris Cook";
        var filter = "(Name eq " + msls._toODataString(defaultValue, ":String") + ")";
        defaultLookup(entity, "Contact", "Contacts", { filter: filter });
    };
    

    在我的代码示例中,主表称为“客户”,查找表称为“联系人”。主表中的“联系人”字段引用联系人表中的条目。 Contacts 表有一个名为“Name”的字段和一个名称设置为“Chris Cook”值的记录(defaultValue 和 filter 变量指的是这种情况)。

    下图显示了正在调试的 screen.Customer 属性:-

    【讨论】:

    • 现在尝试实现此功能,感谢您的回答
    • 我需要一些帮助,以便在您下次活动时应用您的方法,我在上面添加了一些额外的信息,所以希望我能得到这个工作并接受您的回答 :)
    • 没有问题 - 我会尝试在我之前的帖子中提供一些额外的信息
    • Contact, Contacts 是否保持不变?还是应该引用表中的名称(ShippingContacts),即 ContactName
    • 抱歉,我正在分阶段更新以继续引用您的第一篇文章。我已经添加了更多细节。另外,只是为了检查查找表中您将检查与 defaultValue 匹配的字段是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多