locked
Lightswitch HTML Client Javascript: refer to property with help of string variable RRS feed

  • Question

  • Hello.

    I have to set some values programmatically like:

    screen.tblIssueItem.salutation = screen.tblLanguages.data[i].dtRU;

    This works fine. Depending of a selected language {dtRU, dtEN, dtFR, dtJP, dtCH), I want to change the Field (dtRU). Is there a way to refer to the Field with help of an object or a string-variable like?

    Var selLang = null

    switch (screen.tblCountry.selectedItem.fldLanguage) {

                    case “France”;

                                   selLang = “dtFR”,

    screen.tblIssueItem.salutation = screen.tblLanguages.data[i](selLang);

    Of course my example do not work.

    Any suggestions?

    Tuesday, July 22, 2014 9:00 AM

Answers

  • I believe javascript object properties can be referred to by name in brackets:

    obj.prop1 is the same as obj['prop1']

    Try:

    screen.tblIssueItem.salutation = screen.tblLanguages.data[i][selLang];

    or try:

    var lang = screen.tblLanguages.data[i];

    screen.tblIssueItem.salutation = lang[selLang];

    HTH,

    Josh

    • Proposed as answer by Paul Van Bladel Wednesday, July 23, 2014 7:44 PM
    • Marked as answer by Ingo67LS Wednesday, July 23, 2014 9:20 PM
    Wednesday, July 23, 2014 6:55 PM

All replies

  • Hi,

    is there any way to do this? If not I have to do a lot of copy/paste.

    Wednesday, July 23, 2014 8:08 AM
  • I believe javascript object properties can be referred to by name in brackets:

    obj.prop1 is the same as obj['prop1']

    Try:

    screen.tblIssueItem.salutation = screen.tblLanguages.data[i][selLang];

    or try:

    var lang = screen.tblLanguages.data[i];

    screen.tblIssueItem.salutation = lang[selLang];

    HTH,

    Josh

    • Proposed as answer by Paul Van Bladel Wednesday, July 23, 2014 7:44 PM
    • Marked as answer by Ingo67LS Wednesday, July 23, 2014 9:20 PM
    Wednesday, July 23, 2014 6:55 PM
  • Thank you Josh. Works grat. I took this one:

    screen.tblIssueItem.salutation = screen.tblLanguages.data[i][selLang];

    Wednesday, July 23, 2014 9:20 PM