Backbone.js: resetting a collection causes error in model.save - backbone.js

I have a webapp where I am implementing a list of folders. Whenever a folder is clicked, it contents are shown.
After clicking on various folders, thus displaying their contents, I found out that triggering an event on a folder item, multiple models were responding to the event - models for list item appearing in more than one list were not removed when changing folders.
So, I started using this function to remove the collection of list items in a folder.
this.collection.reset()
my problem was solved but now when I try to persist a model to db, I always get the following error...
A "url" property or function must be specified
any idea why this is being caused by this.collection.reset()???

Most likely, you have an event binding somewhere that calls fetch() when reset event is triggered. Look for any bind('reset', ...) statements in your code.

Related

ComboBox inside Gallery

I'm using a gallery to display a list of names I've selected inside the gallery I've inserted a combobox with a bunch of work task codes, this is being saved into a local collection.Gallery with combobox
when I close the app and re-open it the combobox that is beside each name no longer shows the assigned task code.
I have tried placing the task codes in both the DefaultSelectedItems and Items but can not seem to figure out how to retain the selected code once I reopen the app.
I have a save button with the following Clear(Myteam); ForAll(Gallery_team.AllItems, Collect(Myteam,{Position:ComboBox_position.Selected.Value})); SaveData(Myteam "Savedteam")
The use of SaveData is to locally make a save-file of the current state of your collection. It's local, on the device, and not saved somewhere on-prem/cloud related.
If you want to get your SavedDta back into your app, you need to use LoadData first, otherwise the data will stay outside.
For your application, its more wisely to patch it to, for example, a SharePoint list or an excel sheet.

Kendo UI DataSource toJSON is behind by a value

I have an angular application where I am trying to create batch editing in a Kendo Grid. I am manually adding data to the grid, so not using the datasource's transport mechanism, but rather just calling the .data() on the datasource.
When I edit a cell it correctly fires the save event, which also passes the modified data item, however when I call .toJSON() in order to get the raw data of the model, the output of .toJSON() seems to be different from the output of the model itself. It is as if the .toJSON() is behind by an iteration because when I edit the cell again it's the previous value I get.
An example of it can be seen here: http://dojo.telerik.com/ujiSu/5
Try to edit the product name, then in the console you can see the output of model and the output of model.toJSON()
I have tried calling .read() on the datasource before .toJSON() but that results in the datasource being emptied for some reason.
I have also been looking at the dirty property of the model data, forcing it's dirty state to change, but also without any different results.
My goal is to get the raw current data which is displayed in the grid and the datasource.
Any help with this is much appreciated.
In the save event of the grid, the model has not yet been updated. It will be updated by the grid(i.e. pushed into the grid's dataSource) after the save event. This is because the save event is cancel-able via e.preventDefault().
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-save
So, e.model contains the current state of the dataSource item and e.values contains the updated fields until after the save completes, at which point the values in e.values are pushed into the dataSource model.
You either need to combine e.values with e.model in the grid save event or you may want to instead look at the DataSource change event http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#events-change where the action is "itemchange" as that will occur after the grid save event(as long as you haven't cancelled it).

Creating new UI controls programmatically in visual c++

I have just started using visual studio c++ (2010) with windows forms, but have cannot for the life of me find out how to create new UI items in response to events. What I would want to happen is click a button, and have a new row, with a couple of text boxes and buttons appear, with onebutton to delete the row if I keep clicking, more rows will appear, named row0, row1 etcv. I looked at this page, (http://msdn.microsoft.com/en-us/library/aa984255(v=vs.71).aspx), about adding controls programmatically, but when I add a new text box inside a click event, the text box is only created inside the scope of the event (as expected!), but I want to be able to create it insde the newRow click event, but access it and . I thought of making a 'row' class, with row.text and row.deleteButton properties, and at each creation of a row, respective events will be created for button clicks and text edits.
Is there anyway to do this, ie a function that can be created that creates new objects by passing the required name?
The trick for this to work is that you need to have declarations outside of the event handler to keep track of the newly added UI components. In the link you've given the added TextBox is locally scoped within the event function, and this will be removed from the heap (i.e. memory) when the event is finished.
So one solution would be to add a list of UI components to your form, and then have the events add to or remove from this list of components. To get this solution working you possibly need to read up on lists of objects (or possibly dictionaries) and how to handle these.
Sorry for a rather general answer, but the question is also very broad... :)

Backbone-Relational: Does fetch trigger change event for all loaded relations

I did some reading and learned that fetching a collection triggers the reset event for the collection and change event for existing model that changed.
In my backbone app, I fetch a collection and various relations (pages -> partials -> variables). But when I do, the change event is triggered for partials and variables, which is not what I want, they are only loaded.. Not changed!
Am I doing something wrong or is this default behavior?
After some digging in the source, I found out it does. It does a change:[key] event.. I added silent:true to my fetch, so it skips the event triggers.

NullReferenceException thrown in NotifyPropertyChanged when switching views with edit in progress

I have a series of views that are to be displayed depending on the currently selected item in a tree within a parent view. These views are created and registered with the region during the initialization method of the parent view and are being correctly deactivated/activated, therefore giving the effect of swapping in/out the correct view. These views have a single underlying viewmodel as their datacontext, which contains data objects supporting INotifyPropertyChanged.
This solution works if there are no currently outstanding edits in progress within the child view but if there is a edit in progress in a view (i.e. the user has changed the contents of a description but hasn't clicked out of the text box) and that view is deactivated (i.e. the a different tree item is clicked within the parent view, thus causing a de-activation to occur) a NullReferenceException is being thrown in the NotifyPropertyChanged() of the underlying data object attached to the now deactivated view.
What seems to be happening is this:
An edit is started by the user in the child view
The user clicks an item in the tree in the parent view
The controller picks up the change in the selected item in the tree
The current child view is deactivated
The new view is activated
The change from the edit happens to the underlying data object (the set method is getting called)
A change notification event is generated by the data object as a result of this change
A null reference exception is thrown.
Presumably, this change notification event is being sent to the now de-activated view, but the view is not null.
I have not tried this myself, but I believe one solution was to listen for the deactivate event of the view using IActiveAware and cancel any editing.
See if this link helps.

Resources