This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Backbone.js partial model update
I have system where I have to download a series of objects from a rails app. When they arrive, I add more information onto them, (mainly converting coordinates to google's LatLng and other overlays for a map).
The problem is that when I save() the model, ALL the attributes are appended to the request, where I only want some of then to save (I don't want to save the LatLng objects and other overlays, just the attributes that were downloaded)
Possible duplicate question: Backbone.js partial model update
the gist of it is: there is no default support for partially sending a model to the server (at the moment). But if you really need this, it can be done, by overriding the toJSON methods, which are used by the backbone sync functionality.
Related
I am new to backbone.js and I am trying to integrate my work to backbone.js structure. As far as I know the point is to separate the codes in to an MVC pattern and I have some html files that are mainly based on javascript code. For example here: http://bl.ocks.org/mbostock/1256572 I want to make model and view for it. I have found some examples but this one is complicated, for example, draw() function should be in model or view? Or even the function that is used to update the data. I do not know how to separate them in backbone.
All the d3 functions should be contained in a view, the data in a model.
I have a WPF application and am using NHibernate. My question is how do I manage change?
I am not completely sure about the behavior of the IsDirty.
This link describes my problem. The problem list all the information of current environment.
You are trying to address a client side problem using server side technology. Create a viewmodel and put your data in an ObservableCollection and implement the INotifyPropertyChanged interface on the entities as described here
This way you separate the Dirty() logic from NHibernate and make it a "pure" WPF/client issue. In the link it is described in both answers how you can track additions and deletions to/from the collection as well as changes to the properties of the items.
When you are ready to persists your data you hand the dirty records to NHibernate.
Background
I'm working in a client-server REST based application which manages various kinds of information and defines a generic EntitiesCollection which extends Backbone.Collection.
The EntitiesCollection has an API (it extends the Backbone.Collection API) for CRUD operations, filtering, sorting and so on.
My team needs to write a Grid component which can display and manipulate an EntitiesCollection object. This grid will be based on some 3rd party component and we are seriously considering using Kendo.Grid.
The Challange
My first question is whether anyone ever tried to use Kendo.Grid whose data\data-source is actually a Backbone.Collection and whether that is a good and applicable idea at all?
I have seen various articles regarding Kendo and Backbone integration including Derick Bailey's Backbone And Kendo UI: A Beautiful Combination. However, these articles talk about view level integration (wrapping the Kendo.Grid with a Backbone.View). What I am looking for is data level integration - making Kendo.Grid work with Backbone.Collection.
Options
As far as I understand so far Kendo.Grid works with a Kendo.DataSource which in turn holds an internal collection - a Kendo.ObservableArray.
Assuming we are going for it I see several implementation options:
One of the options we discussed is converting our EntitiesCollection to a Kendo.DataSource however this seems to be a non option - the communication with the server has to be done through our own objects.
Replace the Kendo.DataSource with the EntitiesCollection - our EntitiesCollection will implement the Kendo.DataSource API and the grid will work with it as its dataSource object. I don't like this solution since I think I will loose a lot of the functionality that Kendo gives me in the Kendo.DataSource object.
The Kendo.DataSource will wrap our own EntitiesCollection and delegate requests to it.
The Kendo.ObservableArray object contained by the Kendo.DataSource will wrap our EntitiesCollection (see this sample implementation I found online). This approach seem to work with simple use cases however something seems wrong to me - I think that the Backbone.Collection is not the data object (in Kendo terminology) but the DataSource object - since it is the one that interacts with the remote server and fetches the data.
You might be interested in this article that I just posted:
http://www.kendoui.com/blogs/teamblog/posts/13-02-07/wrapping_a_backbone_collection_in_a_kendo_data_datasource.aspx
In it, I walk through the basics of what it takes to build an adapter to use a Backbone.Collection as the backing store for a DataSource, and connect it to a Kendo UI Grid.
I haven't completely solved all of your needs - for example, no paging support - but hopefully this will get you down the path far enough.
All Kendo UI widgets (grid including) can bind only to an instance of the kendo.data.DataSource.
I created the 'kendo-backbone' project to show a possible way to integrate Kendo UI with Backbone. The project wraps an existing Backbone Collection as a Kendo ObservableArray. The latter acts like a simple proxy and works entirely with the Backbone collection.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I would like to start a collection of MVVM-light (w/ RIA Services) Best Practices. There are a number of items I have found to be helpful best practices or best approaches, but would like to hear from others using the MVVM-light toolkit and see what they have found as well.
Please post your best practices as answers to this question.
Basic Usage of MVVM-Light
Intialize the DispatcherHelper in the App.cs file's Application_Startup function
Create ViewModels from the BaseClass
Always Create a ViewModelLocator class, which contains all your view models and is Linked in your application Resources
Use RelayCommands to expose Functions to your view
Learn when to use the DispatchHelper.
Clean-Up Ideas:
When appropriate, add to your ViewModel to clear your DomainContext's EntitySet on Cleanup()?
Call your ViewModelLocator's CleanupSomeVM() function to clear viewmodels when they are no longer actively needed in the application.
I would love to hear from others about when/how you use CleanUp functions. As my application grows, I do feel the need to add some cleanup functions to better manage client memory usage.
For Blendability:
Abstract the Service / Query Implementations to an Interface.
Create 2 classes for each Service Implementation classes (1 for Design, 1 for Production)
Within your each ViewModel, implement its own Service Class (use IsInDesignMode) to create Blendable Service implementations as necessary.
Use a Static variable to hold your DomainContext within the Service Implmentation Class.
Add DispatcherHelper.Initialize() in constructor of ViewModels, but only when in Design Mode. Blend does not load App when loading a page, and this works around that.
For Added Business Logic:
Add Business Logic in the Model first, then in the ViewModel.
Use the Model's partial methods to add logic for appropriate change / update events.
Add Read-Only properties (only getter) to provide summary and calculated values on your model.
For Views:
Always Bind the root to the Locator Object.
Try to keep code-behind logic to layout or custom UI logic only. Avoid referencing your ViewModel.
For Collections:
Use CollectionViewSource for collections in your ViewModels, with a source of the DomainContext's EntitySet
Apply all Filtering, Sorting, and Grouping Logic to the CollectionViewSource in your ViewModel.
After ServiceCalls, Call .View.Refresh() on your CollectionViewSource objects as necessary to update the UI.
For ViewModel coordination (Controller Logic)
Use Messages sparingly, too much complexity can be difficult to manage.
Use the NotificationMessage and PropertyChangedMessage classes to Send/Receive with.
For RIA DomainServices:
Implement any logging in the persist changes function, not the update/insert/delete logic.
During Insert,Update,Delete functions, if you need to reference another Entity via Navigation Property, either check the EntityStatus first, or load the entity from another Context, to prevent EntityStatus conflicts.
For Debugging / Testing:
Check the Output Window for Binding Errors and Fix them. Binding Errors fail silently to the user, but degrade application performance and expected behavior.
Create Unit Tests in Silverlight to verify any added Model / Business Logic
Create Unit Test project to test server-side logic and functions
For Entity Framework:
Keep 1-to-1 Match of EntitiesContext to Domain Service. Trying to split this another way causes issues.
Do NOT use the [Composition] attribute unless you fully intend to spend a lot of time carefully building your Insert, Update, and Delete logic.
Use a separate service to serve custom types back to your RIA Client. Do not add them to your DomainService for your EntityFramework Object
Perform Server-side update/integration logic (such as updating other systems) in the PersistChangeSet function, not in the Insert, Update, Delete functions. This will prevent you from accidentally pulling in an entity via Navigation Properties, which will leave your detached version non-updated.
Create an additional Context to find current values during update/integration logic.
In looking through samples I have seen a number of examples where it is possible to present data within a wpf applicaiton by binding to collections. However I was wondering is it possible to write to a collection from an applicaiton. Say for example i have 2 or more fields such as names and I wanted to have hte ability to add up to three names in my application ( all stored in memory). Will collections serve this purpose. In the past with asp.net I have done this by creating data tables and storing values on the fly or during the session. I am trying to learn WPF and I was wondering if collections work in the same fashion?
If so could you please post an example or point me to references that show examples of this?
Thank you in advance.
Use ObservableCollection as a datasource if you want UI to update on the changes you made to collection from your code.
See ObservableCollection<(Of <(T>)>) Class It also contains quite a good sample.