backbone-relational

Backbone.js toJSON() not including attributes

折月煮酒 提交于 2020-01-15 11:44:07
问题 I really can't wrap my head around this one. For some reason, (and I suspect it has something to do with asynchronous requests) my model attribute is not being converted properly using the toJSON() function. FWIW, I'm attempting to do lazy loading with django-relational fetchRelated(). Here's where I made the fetchRelated() request and create a new view. $.when(usermodel.fetchRelated("movies")).then(function(){ var newview = new UserMovieList({model: usermodel}); newview.render(); }); And

Backbone outputing empty array for collection.models?

耗尽温柔 提交于 2019-12-23 02:36:14
问题 Having a problem where if I do apples = new Apples apples.fetch() console.log apples console.log apples.models console.log apples will out put the Apples Collection, with models: Array(10) listed inside the object. But, console.log apples.models outputs an empty array. Why does this happen? Thanks in advance. 回答1: Are you trying to console.log the collection right after executing the fecth() method or waiting for the callback to be executed by using apples.on('reset', function(){ console.log

Saving Entries to Database Relationship (many-to-many) Table from a Backbone Project

戏子无情 提交于 2019-12-23 01:54:13
问题 I currently have two Backbone models: user and project. I would like to have a Backbone view containing a form that enables the creation of a new project, and the association of currently existing users (entries from the database users table) with this project. When a user completes this form and clicks the save button, the new project should be saved into the database (in the projects table) and the relationship between the saved project and the related users should be saved into a

Foreign key populated with an object

落爺英雄遲暮 提交于 2019-12-22 04:05:51
问题 I would like to make a relation between two models User and Task using backbone-relational. The relation between the two models is the following: taskModel.creator_id = userModel.id // TaskModel var TaskModel = Backbone.RelationalModel.extend({ relations: [ { type: Backbone.HasOne, key: 'creator', keySource: 'creator_id', relatedModel: Users } ], // some code }); // Task collection var TaskCollection = Backbone.Collection.extend({ model: TaskModel, // some code }); // User Model var User =

Backbone-relational hasmany best practices

馋奶兔 提交于 2019-12-22 03:58:14
问题 I am new to Backbone-relational, I am not sure what is the right way to use HasMany. I have a Parent model which have many children (by "many" I mean thousands of children). In order to avoid performance issue, I query children by their foreign key: /child/?parent=1 , instead of create a huge list of child_ids in Parent . But seems this is not the way Backbone-relational work. So I am wondering what is the right way to handle this. 1, Change my json api to include list of child id in parent,

How to handle relations in backbone.js [duplicate]

只谈情不闲聊 提交于 2019-12-20 09:41:05
问题 This question already has answers here : backbone.js - handling model relationships in a RESTful way (4 answers) Closed 3 years ago . I'm stuck with how to design my backbone.js application regarding to my model relationships. If I have an event model , that has a couple of relationships, say a user model can have many events and the event model in turn can have many comments and participations. A user can have many comments and the participation can have one user and one event. Wow, what a

Templates for nested attributes with Backbone

元气小坏坏 提交于 2019-12-13 00:29:07
问题 I have an Appointment model, each instance of which has a Client . Here's my template for editing an appointment: <form id="edit-appointment" name="appointment" class="mobile_friendly"> <div class="field"> <input type="text" name="start_time_ymd" id="start_time_ymd" value="<%= start_time_ymd %>" placeholder="Start Date"> <input type="text" name="start_time_time" id="start_time_time" value="<%= start_time_time %>" placeholder="Start Time"> </div> <div class="field"> <input type="text" name=

Can't get Backbone-relational to work with AMD (RequireJS)

我怕爱的太早我们不能终老 提交于 2019-12-12 04:23:36
问题 I have the following Backbone router definition in CoffeeScript: // appointments_router.js.coffee define ["app", "appointment"], (App) -> class Snip.Routers.AppointmentsRouter extends Backbone.Router initialize: (options) -> @appointments = new Snip.Collections.AppointmentsCollection() @appointments.reset options.appointments Here is the "appointment" module on which it depends: // appointment.js.coffee define ["app", "relational"], (App) -> class Snip.Models.Appointment extends Backbone

creating nested structure with backbone-relational

送分小仙女□ 提交于 2019-12-12 01:36:33
问题 I'm trying to create a three cascading dropdown lists. First one constains projects, second contains tasks for selected project and the last one sites for selected task. I want to use the Backbone-Relational plugin, but have hard time to create the proper relations. That's my first time with this plugin. Code so far: App.Models.ProjectItem = Backbone.RelationalModel.extend({ default: { id: 0, name: '' }, relations: [{ type: Backbone.HasMany, key: 'tasks', relatedModel: App.Models.TaskItem, /

Loading Backbone.Relational using Use! plugin

∥☆過路亽.° 提交于 2019-12-12 00:36:37
问题 Backbone Relational is not an AMD compliant library, so I've gone ahead and found the use plugin to ensure underscore and backbone are both loaded as dependencies. Here is my config file require.config({ baseUrl: '../global/js', paths: { use: 'libs/utilities/use', jquery: 'libs/jquery/jquery-min', underscore: 'libs/underscore/underscore-min', backbone: 'libs/backbone/backbone-optamd3-min', text: 'libs/require/text', relational: 'libs/backbone/backbone-relational' }, use: { "relational": {