Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created April 3, 2014 18:47
Show Gist options
  • Save justintoth/9960464 to your computer and use it in GitHub Desktop.
Save justintoth/9960464 to your computer and use it in GitHub Desktop.
function bindCategories(data) {
//ko.mapping.fromJS(data, mappingOptions, viewModel.cannedResponseCategoriesViewModel);
viewModel.cannedResponseCategoriesViewModel = ko.mapping.fromJS(data, mapping);
vjq.each(viewModel.cannedResponseCategoriesViewModel(), function (index, item) {
item.Label.subscribe(function (value) {
alert('subscribed');
Velaro.PremadeCategory.Update(ko.toJS(item));
});
subscribeInnerElements(item.Children);
});
//vjq.each(viewModel.cannedResponseCategoriesViewModel, function (index, item) {
// viewModel.childCannedResponseCategoriesViewModel.concat(item.Children());
// });
ko.applyBindings(viewModel.cannedResponseCategoriesViewModel, vjq('#categories-list')[0]);
if (data.length > 0) {
Velaro.PremadeMessage.GetByCategory(data[0].PremadeCategoryID, messagesLoadedOnStart);
}
};
function subscribeInnerElements(children) {
vjq.each(children(), function (index, item) {
for (var prop in item) {
if (ko.isObservable(item[prop])) {
item[prop].subscribe(function (value) {
Velaro.PremadeCategory.Update(ko.toJS(item));
});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment