Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Lightswitch HTML客户端-在创建屏幕时设置模式选择器值_Javascript_Visual Studio Lightswitch_Lightswitch 2013 - Fatal编程技术网

Javascript Lightswitch HTML客户端-在创建屏幕时设置模式选择器值

Javascript Lightswitch HTML客户端-在创建屏幕时设置模式选择器值,javascript,visual-studio-lightswitch,lightswitch-2013,Javascript,Visual Studio Lightswitch,Lightswitch 2013,我现在对此做了很多研究,没有一个例子是有用的或适用的。我想做的是,当用户加载Add屏幕时,我希望细节选择器在创建屏幕时显示一个名称,而不是每次都要选择它。我相信这是可以做到的,但我的javascript技能是缺乏的 谢谢你的帮助, 下面是一个例子: 此名称存储在一个表中,可以在此模式选择器/详细信息选择器中搜索,但正如您所想象的,如果此值需要50%的时间,则手动添加它不仅耗时,而且会变得有点乏味 在每个项目上按post render后,可以使用contentItem.value或element

我现在对此做了很多研究,没有一个例子是有用的或适用的。我想做的是,当用户加载Add屏幕时,我希望细节选择器在创建屏幕时显示一个名称,而不是每次都要选择它。我相信这是可以做到的,但我的javascript技能是缺乏的

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

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

在每个项目上按
post render
后,可以使用
contentItem.value
element.innerText
来操作文本框,但这不适用于这种类型的控件,我会看到以下错误:

以下是一些有用的信息,可能会有所帮助:

  • 项目数据(数据源)
  • 主屏幕参考OrderRequest
  • 外键链接引用ShippingContact,并在DetailsSpicker上搜索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 });

有了相同的需求,我们实现了以下帮助函数:-

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];
    });
};
在您的情况下,screen.Customer应更改为screen.OrderRequest,“Contact”应更改为“CustomerName”,而“Contacts”应更改为“ShippingContacts”。此外,根据您的查找表中有一个名为ContactName的字段,筛选字符串需要引用ContactName而不仅仅是name。

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

myapp.AddEditCustomer.created = function (screen) {
    var defaultValue = "Chris Cook";
    var filter = "(Name eq " + msls._toODataString(defaultValue, ":String") + ")";
    defaultLookup(screen.Customer, "Contact", "Contacts", { filter: filter });
};
myapp.Customer.created = function (entity) {
    var defaultValue = "Chris Cook";
    var filter = "(Name eq " + msls._toODataString(defaultValue, ":String") + ")";
    defaultLookup(entity, "Contact", "Contacts", { filter: filter });
};
在我的代码示例中,主表名为“Customers”,查找表名为“Contacts”。主表中的“Contact”字段引用Contacts表中的一个条目。Contacts表中有一个名为“Name”的字段和一个名为“Chris Cook”的记录(defaultValue和filter变量表示这种情况)。

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


我现在就开始实施,谢谢你的回答。我需要一些帮助,以便在下次活动时应用你的方法。我在上面添加了一些附加信息,希望我能使这项工作正常进行,并接受你的回答:)没问题-我将尝试在我以前的Post中提供一些附加信息。联系人是否保持不变?或者这是否应引用表中的名称(ShippingContacts)这是ContactNameSorry,我正在分阶段更新,以继续引用您的第一篇文章。我添加了更多详细信息。另外,只是为了检查查找表中您将要检查与defaultValue匹配的字段是什么?