lightswitch以编程方式添加行

时间:2015-05-22 05:39:18

标签: visual-studio-lightswitch

我有这种方法来插入从下拉列表中选择的新条件。该列表是多选的,因此您可以选择多个项目。如果我从列表中选择4个项目,则会在数据库中插入4个项目,但所有值都相同。它将选择最后一项并插入4次。

例如,如果我选择A B C D并且我检查数据库,它将显示D四次。我相信这与这行代码有关,但我坚持下去。

myapp.AuditAssets.Submit_execute = function (screen) {

    var list = screen.findContentItem("Conditions");
    var selected = lsWire.getSelectedListItems(list);

    _.forEach(selected, function(item) {

        var assetcondition = myapp.activeDataWorkspace.JMSData.AssetConditions.addNew();
        assetcondition.Asset = screen.ScannedAssetsByProject.selectedItem;
        assetcondition.Condition = screen.Conditions.selectedItem;
    });
}

1 个答案:

答案 0 :(得分:-1)

试试这个:

myapp.AuditAssets.Submit_execute = function (screen) {
    var list = screen.findContentItem("Conditions");
    var selected = lsWire.getSelectedListItems(list);

    _.forEach(selected, function(item) {
        var assetcondition = myapp.activeDataWorkspace.JMSData.AssetConditions.addNew();
        assetcondition.Asset = screen.ScannedAssetsByProject.selectedItem;
        assetcondition.Condition = item;
    });
}