2

I am creating dropdown values for my customization. The attribute 'value' in options is empty "". I am loading the KeywordObj . can anyone help?

Here's my code -

 var keywordObj = $models.getItem(tcmId);
                    var desc = "";
                    if (keywordObj) {
                        function onKeywordLoaded() {
                            $evt.removeEventHandler(keywordObj, "load", onKeywordLoaded);
                            desc = keywordObj.getDescription();
                        }
                        if (keywordObj.isLoaded(true)) {
                            onKeywordLoaded();
                        }
                        else {
                            $evt.addEventHandler(keywordObj, "load", onKeywordLoaded);
                            keywordObj.load();
                        }
                    }
                    var opt = new Option(title, desc);
                    opt.setAttribute("tcmid", tcmId);    
2

This is because of how JavaScript works (async)

The assignment var opt = new Option(title, desc); happens (most of the time) before the call to keywordObj.load() has finished. So the desc variable is still empty if you want to use it there.

The easiest solution is to move these 2 lines:

var opt = new Option(title, desc);
opt.setAttribute("tcmid", tcmId);    

inside the onKeywordLoaded callback.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.