Skip to content

Instantly share code, notes, and snippets.

@dfch
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfch/d64cfb6e21892dc8cc26 to your computer and use it in GitHub Desktop.
Save dfch/d64cfb6e21892dc8cc26 to your computer and use it in GitHub Desktop.
[NoBrainer] Changing LightSwitch HTML Cascading choiceLists with JayData
// global - or wherever it suits you
var ctxApplicationData = "ctxApplicationData";
// somewhere at the very start of the application
$(function () {
var svcApplicationData = msls.application.rootUri + "/ApplicationData.svc";
$data.initService(svcApplicationData)
.then(function (context) {
// manage your data through context with JSLQ
console.log(svcApplicationData + ": we are here...");
ctxApplicationData = context;
});
} // document.ready()
// AddFuncensteinScreen.lsml.js
myapp.AddFuncensteinScreen.created = function (screen) {
// we add a change listener to the parent control
screen.addChangeListener("FuncomaticListControl", addChangeListenerFuncomaticListControl);
}
function addChangeListenerFuncomaticListControl(e) {
value = e.currentTarget.FuncomaticListControl;
console.log("FuncomaticListControl: '" + value + "'");
var dataChoices = new Array();
function renderData(_list) {
_list.forEach(function (item) {
console.log(item.Name);
dataChoices.push({ value: item.Id, stringValue: item.Name });
});
var ChildDropDown = e.currentTarget.details.screen.findContentItem("FuncyChildListControl");
ChildDropDown.choiceList = dataChoices;
ChildDropDown.dispatchChange("choiceList");
ChildDropDown.dispatchChange("value");
}
ctxApplicationData.FuncyItems
.filter(function (e) {
(e.Funcomatic.Name == value)
})
.orderBy("it.Name")
.map(function (e) {
return e
})
.toArray(renderData);
} // addChangeListenerFuncomaticListControl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment