Currently, we are using nested attributes that are getting saved in the collection view being sent back to the server. For some reason, Marionette creates the new view in the collection just fine, but then it goes through the collection, closing,destroying,and rerendering all the views throughout the collection. Does anybody know what it could possibly be doing that? Just attributes that are not recognized that would have the whole collection updated many times? I also tried
.save(null,{merge:false})
which somewhat helped but still had some crazy issues creating views in the collection.
Edit: Basically, when I load things from the server everything is fine. After I save a model in the collection, things start to go crazy by firing different events that will add/remove from it.
Related
I have a problem that seems pretty specific to my plugin but I don't know enough about backbone.js to solve.
Pretext:
My plugin injects some DOM elements to control its features and script elements to interface with the page and send events to my plugin's backend.
The Problem: Backbone does some sort of cleaning of the page and removes all of my elements but leaves the original page alone. I know this is backbone because I traced the remove event to part of backbones script. I also know its not plug.dj because they have no reference in their code to anything that could detect my elements. I need to know how to prevent backbone.js from removing my elements or find a way to detect when backbone is done culling the page so I can inject at that time.
If anyone knows of a flag I can put on the elements to prevent this from happening or some sort of flag that tells me backbone is finished, it would be greatly appreciated.
My plugins code is available here: https://github.com/tyduptyler13/PlugPlus/tree/dev (Keep in mind its the dev branch! Master branch is the last stable version, the dev has some new beta features I was testing.)
This code is the most up to date version available to the public and all versions have this issue after plug.dj made the change to backbone.js.
For plug.dj code you will need to dig manually on their site http://plug.dj/
And finally, to test their site with my code you will need to add it from the chrome store.
I ended up ignoring the fact that backbone was culling my content by doing an interval based check to see if backbone was finished "rendering" the page. If you add content after backbone has finished it won't overwrite it or remove it.
I have a tree of models and I'd like to have them load from one big JSON request up front and then be able to change them one at a time without saving the whole tree or reloading the whole tree and without making two versions of each model.
The problem I've encountered is if each of the submodels has a keySource they won't upfront load, but without a keySource you can't do an individual load or save.
My content in the upfront load is the entire object tree fully connected (no id lists) because I didn't see a way around this. Is that the problem? Or is what I'm trying to do just not possible without two versions of the models that are somehow connected?
It is possible to do selective saving if you override the save method of Backbone.Model. I wrote an article on this topic. Your choice if you want to create little sub-models that represent parts of your model. When those are changed, you can get their changedAttributes hash and pass it to the save of the main model. With the method I discuss in the article it is entirely possible to post only parts of your model during a save.
Have you considered using a collection for this? You could override the parse method of collection to create your models. Just a thought.
I'm using Siaqodb for my client side database engine in a Sync Framework silverlight project. I've switched to siaqodb because microsofts client side solution loads the entire database into memory at once and, as such, has a hard time handling large data.
I've bound a list of SiaqodbOfflineEntity objects to a silverlight datagrid in order to create an editable datagrid. Unlike microsofts solution, you can't bind the database entries directly to the datagrid. You have to query the database and bind a list of in memory objects to the datagrid. This causes a problem in that the database isn't immediatly updated when the datagrid cell is changed. I'm trying to find the best way to handle updates to the database after a change in the cell. I can't just update each item to the database because the siaqodb engine will mark the item as dirty even if no change was made to the object. This will cause conflicts when trying to sync. holding a cached version of the original list and then comparing each property of each object to find which ones have changed seems like it would work, but seems to be a bit cumbersome. I've also tried looking at some of the datagrids events but RowEditEnded doesn't appear to fire when a cell is edited and CurrentCellChanged seems to fire whenever I switch rows (odd).
There's got to be a better solution to this. Anyone have any ideas?
So I've gotten this to work by changing my offline entity classes to implement iNotifyPropertyChange and I think this is a reasonable solution. I set the PropertyChanged event to a function that saves the object to the database. There is a VS package called notifypropertyweaver that will inject this code at compile time, reducing the amount of work needed to be done on auto-generated entity code.
I have a WPF DataGrid for which data comes from a stored procedure. I want to know how can I virtualize that data?. I am using ADO.NET Entity Framework. My data in the database changes regularly and it needs to be fetched regularly through my stored procedure. Thanks in Advance.
Try to have a look at this post in order to see if it is useful to you. It is a generic solution to virtualize a collection. There is a sample too. Basically it works by proxing the data inside the collection to intercept when the UI observe the element, when it occours, a page is fetched. The only drawback is that the entity in the collection as to be declared as "proxable", so it must be public and with virtual properties.
I'm learning about MVVM and one of the things I don't get is how the model and the view model are supposed to communicate. I also don't understand whether they are separate classes, composite classes, or whether the ModelView is supposed to inherit from the model.
I need to get some data from a web service, so I think the model should be responsible with it and make the appropriate web service calls. But since these requests really originate in the view as a result of the user wanting to see some information it means the ModelView has to forward that request to the model somehow, then provide an asynchronous notification mechanism so that the view isn't stuck while the model asynchronously retrieves the data. To summarize, suppose we have the following use case:
View: ComboBox --> bound to List in ModelView. Model view is connected to Model in (?????) way. The data that will populate the list can be retrieved by a web service call. How does this scenario work?
Let's make your scenario a bit more complicated: user clicks a button and then a list needs to be populated with a data that comes from a web service.
In this scenario:
View's list is bound to ObservableCollection in ViewModel.
View's button is bound to a command in ViewModel.
ViewModel's command's handler will fire an asynchronous request to a web service and subscribe a listener that will handle a response.
The response handler will populate the observable collection with the items from the response once it's received. Since View is bound to the ObservableCollection it will automagically update its list on the screen.
Now whether you encapsulate a web service call in an another class (e.g. Model) or leave it in ViewModel highly depends on your own preferences (e.g. having it in a model allows to to easily test ViewModel by injecting a mock rather than having a web service running, etc.)
In short, the view model is fully aware of the model and can interact with it directly. Don't overthink the interaction between them. The only double-blind relationship is that between the view and the view model.
I think it is worth mentioning that you do not always need three different classes for your MVVM "combos". The V will always be its own class, the VM will probably also need its own class (I don't think it has to, though), but the M can be the same across the entire project if that suits your application. If you are building a small application, let's say you only have 10-15 different service methods in total, it will probably make sense to have one single class responsible for calling your web service, handling errors and making the asynch callbacks to the various VMs. And if you are building a really small app, maybe it will make sense to have only one VM and, say, 2-3 Views that bind to that single VM. Maybe in that case you don't even need a separate Model class at all, just call the web service directly from your VM. After all, you will have created a service reference to that web service. The generated proxy classes will then act as your Model.
What I am trying to point out is that when reading about MVVM it is easy to assume that there will always be three physical files for each MVVM "combo". That is what I thought when I started experimenting with MVVM, and I thought to myself "Wow, that's a lot of files. And Wow, what if I have some common methods in the web service that need to be called by multiple Model classes, then I will have tons of duplicated code all over the place.". But when my head cleared I realized that it's up to me to decide what works best in my app.