【问题标题】:lightswitch html client set default value for details pickerlightswitch html客户端为详细信息选择器设置默认值
【发布时间】:2015-09-18 17:19:49
【问题描述】:

我正在尝试为 lightswitch html 客户端中的详细信息选择器设置默认值。我试过了:

var picker = screen.findContentItem("SelectedItemType"); picker.value = "监视器";

我正在尝试将它设置在屏幕的 created 方法中。

谢谢

【问题讨论】:

标签: html client visual-studio-lightswitch


【解决方案1】:

语法正确。并且创建的事件应该可以工作。

试试:

  1. screen.Property_MyString = "默认值";

工作示例:

  1. 打开屏幕。
  2. 点击“添加数据项”->“本地属性”->“字符串”
  3. 给它命名:例如'Property_MyString'
  4. 点击“写代码”->“创建”
  5. 类型:screen.Property_MyString = "默认值";
  6. 将新属性添加到您的屏幕。

如果要设置详细信息选择器的默认值:

var filter = "Id eq " + msls._toODataString(YourDefaultValueId, ":Int64");
myapp.activeDataWorkspace.YOURDATASOURCE.YOURDATATABLE.filter(filter).execute().then(function (result) {
    var defaultValue = result.results[0];
    screen.YOURPROPERTY = defaultValue;
});

【讨论】:

  • 当我使用显示名称时发生的事情是它更改了内容项的标签并没有设置默认值。
  • 啊,你是对的!一秒钟刚喝了杯咖啡,我会更新答案。
  • 仍在尝试理解它,伙计
  • 请参阅将默认值添加到本地字符串属性是可以的,它只是来自数据库的本地属性。下拉列表不会填充我的默认值
  • 嘿,伙计没听懂,我现在正在做另一部分,但感谢您的帮助
【解决方案2】:

看看我自己发的这个帖子,应该可以解决你的问题,如果有什么问题可以随时提问:)

Lightswitch HTML Client - set modal picker value when screen created

但这是您应该使用的代码:

  1. 将此粘贴​​到 JS 文档的第 2 行:

    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.ProjectHandlerData[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];
    });
    };
    
  2. 在您的屏幕创建事件上,输入此代码(修改屏幕值和表名以匹配您的:

    myapp.AddEditHolidayRequest.created = 函数(屏幕){

    var defaultValue = "Monitor";
    var filter = "(ProductName eq " + msls._toODataString(defaultValue, ":String") + ")";
    defaultLookup(screen.Order, "Part", "Parts", { filter: filter });
    

    }

ProductName:这是在存储名称“监视器”的数据库表中调用的列名。

screen.Order 是您使用的任何屏幕

1.“Part”和2.“Parts”的区别

  1. 如果您要从解决方案资源管理器中打开表格,则在数据源文件夹下,此处顶部显示的名称位于编号 1 中

  2. 将是您的表的名称,如右侧解决方案资源管理器中的数据源下所示

【讨论】:

  • myapp.activeDataWorkspace.WMSData.GetItemTypeByName("MONITOR").execute().then(function (response) { screen.SelectedItemType = response.results[0]; });
  • 我创建了一个名为 GetItemTypeByName 的查询并有一个字符串参数
猜你喜欢
  • 1970-01-01
  • 2015-04-16
  • 1970-01-01
  • 2017-10-02
  • 2017-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多