Skip to content

Instantly share code, notes, and snippets.

@samdelagarza
Created February 26, 2011 22:13
Show Gist options
  • Save samdelagarza/845670 to your computer and use it in GitHub Desktop.
Save samdelagarza/845670 to your computer and use it in GitHub Desktop.
_contracts = new _widgetCollections.Contracts();
_contractDropDown = new _widgetViews.contractDropDown({
collection: _contracts
});
And in a seperate file this is the collection definition:
(function (m, $, undefined) {
(function (c) {
(function (criteria) {
(function (widgets) {
(function (models) {
models.Contract = Backbone.Model.extend({
Value: "",
Text: ""
});
}(widgets.models = widgets.models || {}));
(function (collections) {
collections.Contracts = Backbone.Collection.extend({
model: widgets.models.Contract,
parse: function (xhrResponse) {
var r = _.map(xhrResponse, function (contract) {
return {
Text: contract.Text,
Value: contract.Value
};
})
return r;
}
});
}(widgets.collections = widgets.collections || {}));
(function (views) {
views.contractDropDown = Backbone.View.extend({
tagName: "select",
template: "<option value='{{id}}'>{{name}}</option>",
initialize: function () {
_.bindAll(this, 'render');
this.collection.bind('refresh', this.render);
},
render: function () {
var
self = this,
contractCombobox = $('#ContractList').data('tComboBox');
if (contractCombobox !== undefined) {
var telerikDs = _.map(self.collection.models, function (c) {
return c.toJSON();
});
contractCombobox.dataBind(telerikDs);
}
return this;
}
});
}(widgets.views = widgets.views || {}));
}(criteria.widgets = criteria.widgets || {}));
}(c.criteria = c.criteria || {}));
}(m.c= m.c|| {}));
}(window.m= window.m|| {}, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment