UserCollection = Backbone.Collection.extend({ model: User }); myUserCollection = new UserCollection(); myUserCollection.reset([ { name: "Bob", age: 25 }, { name: "Foo", age: 26 } ]);
/** * Creates a new Splunk user from a username, password, and role. * Usernames must be unique on the system, and are used by the user to log * in to Splunk. * * @param name The username for the new user. * @param password The password for the new user. * @param role The role to assign to the new user. * @return The new user. */ public User create(String name, String password, String role) { return create(name, password, role, null); }
/** * Returns a collection of Splunk users. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of users. */ public UserCollection getUsers(Args args) { return new UserCollection(this, args); }
/** * Creates a new Splunk user from a username, password, and array of * roles. * Usernames must be unique on the system, and are used by the user to log * in to Splunk. * * @param name The username for the new user. * @param password The password for the new user. * @param roles Array of roles to assign to the new user. * @return The new user. */ public User create(String name, String password, String[] roles) { return create(name, password, roles, null); }
var UserListView = Backbone.View.extend({ el: ".page", initialize: function() { this.users = new UserCollection(); }, render: function() { var that = this; this.users.fetch({ success:function(users){ console.log(users.models); var template = _.template($('#user-list-template').html(), {users : users.models}); that.$el.html(template); } }) } });
/** * Creates a new Splunk user from a username, password, role, and * additional arguments. * Usernames must be unique on the system, and are used by the user to log * in to Splunk. * * @param name The username for the new user. * @param password The password for the new user. * @param role The role to assign to the new user. * @param args A map of additional arguments. For a list of available * parameters, see * <a href="http://dev.splunk.com/view/SP-CAAAEJ7#userauthparams" * target="_blank">User authentication parameters</a> on * <a href="http://dev.splunk.com/view/SP-CAAAEJ7" * target="_blank">dev.splunk.com</a>. * @return The new user. */ public User create(String name, String password, String role, Map args) { args = Args.create(args); args.put("password", password); args.put("roles", role); return create(name.toLowerCase(), args); }
initialize: function() { this.collection = new UserCollection(); this.collection.fetch(); this.collection.on("reset", this.render, this); this.render(); },
/** * Creates a new Splunk user from a username, password, array of * roles, and additional arguments. * Usernames must be unique on the system, and are used by the user to log * in to Splunk. * * @param name The username for the new user. * @param password The password for the new user. * @param roles Array of roles to assign to the new user. * @param args A map of additional arguments. For a list of available * parameters, see * <a href="http://dev.splunk.com/view/SP-CAAAEJ7#userauthparams" * target="_blank">User authentication parameters</a> on * <a href="http://dev.splunk.com/view/SP-CAAAEJ7" * target="_blank">dev.splunk.com</a> . * @return The new user. */ public User create(String name, String password, String[] roles, Map args) { args = Args.create(args); args.put("password", password); args.put("roles", roles); return create(name.toLowerCase(), args); } }
var UserModel = Backbone.Model.extend({ // String name is mapped to an object with the name property parse: function(name) { return { name: name }; } }); var UserCollection = Backbone.Collection.extend({ model: UserModel }); var collection = new UserCollection(['Ann', 'Joe', 'Jim', 'Bob'], {parse: true}); console.log(collection.at(0).get('name'));
initialize: function(){ //..... your code in initialize this.userModel = null; this.collection = new UserCollection(); }, signIn: function(e) { e.preventDefault(); var here = this; this.collection.fetch({ type: 'POST', url: 'http://localhost/app/api/User.php', dataType: "json", data: $.param({ req: "REQUSERSIGNIN", platform: "WEB", useremail: $('#userSignIn #userEmail').val(), userpass: $('#userSignIn #userPassword').val() }), success: function(data) { var user = {handle: data.HANDLE,email: data.EMAIL,uuid: data.UUIDUSER,userpic: data.USERPIC,tokenlogin: data.TOKENLOGIN}; here.userModel = new UserModel(user); here.collection.addUser(here.userModel); } }); }
var InterviewersSelect = Backbone.View.extend({ initialize: function () { this.template = _.template(interviewersTemplate); this.collection = new UserCollection(); }, render: function () { var self = this; this.collection.fetch({ data: { role: "developer" }, success: function(collection) { var interviewers = collection.map(function(item) { return item.toJSON(); }); self.$el.html(self.template({interviewers: interviewers})); } }); return this; } });
this.users = new UserCollection(); },
var users = new UserCollection(); var view = new UsersView({collection: users}); users.fetch();