I'm having a difficult time in implementing MVC's View and View's responsibilities. By the way I'm implementing the MVC in new way, not smalltalk's traditional way (controller between model and view. View does not have a relation with model vice versa)
My problem is sth like following. My View have a test list shown as a table, each table row corrensponds to a single test and user can select more than one test. And each test (row) may have 0 or more options for the selected test. After clicking 'start test' button, my application is supposed to execute selected tests with their selected options.
How should I implement this part of my application so that controller is informed about the selected tests and parameters? Should the view provide the information about selected tests and parameters?(makes View a little intelligent, not dumb as desirerd ?)
Should the view provide information by going through all rows of table and checking the parameters(hence no dedicated 'selected tests and params structure' or should it store selected tests and test parameters in a dedicated structure and post it when controller requires?
Or controller knows the view and it can grab all the data it needs from View?
I would expect the controller to have intimate knowledge of both the view and model. So I prefer "...controller knows the view and it can grab all the data it needs from View", as it means you keep the most difficult part to test, the view, as simple as possible.
Related
How implement adapter in xamarin.forms (xaml) simple ? But all example is for andorid or iOS. Can writing example for xamarin.forms
Adapters are part of the native Android UI framework for displaying data using the MVC pattern. In the world of Xamarin Forms, the best analogue is a ViewModel and the Model View ViewModel pattern (MVVM). In its simplest form, a ViewModel is any class that the view binds to by having an instance of that class assigned to the View's BindingContext. This is, by itself, enough to perform one-time binding where the values in that class' properties are read by the View when the View is created. If you want more advanced binding where updates to the underlying ViewModel are reflected in the View, you need to implement INotifyPropertyChanged and send notifications to the View. Also, rather than roll your own, I would recommend that you look into using an existing MVVM framework such as MvvmLight.
To acheieve what you are looking for, you would have a ViewModel expose a property that is of an IEnumerable or IList. You could then bind one of the repeating views such as ListView to this property and see the underlying data reflected in the view. By implementing INotifyPropertyChanged (or using a framework that does that for you), you can have new items added to the collections exposed by those properties appear in the UI.
My application has a list view (master) containing a data sheet view in a sub view element.
In the list view, I would like to use some control like a button or a combo box to filter the data in the sub view. How can I pass a parameter for the filter from the master view to the sub view?
I don't believe the scenario you are looking at here will be directly possible within the Access web app context. Let me explain.
In Access 2013 web apps, there is no macro action available to requery or refresh a specific control on a view. The same goes for trying to refresh a Subview control on a view. The only way you can pass parameters to a different view in the web app context is by using the OpenPopup macro action. In that case the view will open as a popup which is not what you want here either.
So you might not be able to achieve your end goal. One suggestion that might work is to have say an unbound text box control on the main parent view. For the Subview control, use that unbound control as the Master Field (in the property list). Access will attempt to match records from this unbound control to whatever field you designate as the Child Field property. If you update that unbound text box control on the main view, Access should filter the results in the Subview. I "think" that will work.
It works in my app. SubForm updates with filter when focus leaves the txtbox. Unfortunately, you can only search one field per subview as it is set as a property at design time and AFAIK there is no way to change at runtime.
I'm looking at creating a google maps component. But I would like it to be self contained so it will have its own model, controllers and views. So for example the component will fetch its own data from the server and I'll also be able to refresh the data when needed. Ideally I'd simply add the component to the current template that is showing, so for example: {{map-view}} and then everything the component needs to do will take care of its self.
The component will also need to listen to triggered events from other controllers as a user will be able to search for a specific location and the map will need to change its position.
Is this possible to do in EmberJS? As I haven't found anything like this, specially when having its own model. I know there is a component in EmberJS but it seems very limited. Am I wrong in thinking this?
the controller cannot have its own model all values must be passed to component. Please refer to ember docs and this Discussion
You can make a google map component and pass the location and marker data to the component. this data will get updated due to ember data binding.
so you can have something like this
{{map-view location=userEnteredValue}}
you can search for ember component talk by Kris Selden on youtube which includes a google map component good for you to start with.
updated
https://gist.github.com/krisselden/8189650
I'm been playing with ember.js off and on the last few months and always end up asking "what role does the controller play" because it usually looks something like this when I'm done
App.Controller = Ember.Controller.extend({
content: null
});
If I have any basic validation requirements I tend to do these in the view itself.
If I need to populate a controllers content I do this in the router (though I'd prefer to reduce the # of responsibilities this object seems to have in the current version of ember).
My models are persisted using a separate adapter via ember-data with some domain logic like behavior when needed.
What I'm left with in every app I've built is a thin (very very logic less) controller as shown above. I do find this is a good place to do sorting / pagination / search / filter / etc on the items but what else should this controller object be responsible for in a well design ember.js app?
As you say, sorting / pagination / search / filter (BTW most of those is supported by Ember.ArrayController)
I think other stuff could be computed properties around the content (model), and then the view relies on those computed properties instead of doing the job by itself.
Perhaps it could be a good place to track and persist a view state (for example collapse/expand), which cannot be persisted in the view itself because it's destroyed/created at each time.
I am listing products as table rows, each row contains input fields for specifying the quantity of products.
I made a Fiddle for it here, http://jsfiddle.net/kroofy/4jTa8/19/
As you can see, after the input in the Qty field have been made, the whole row render again. And because of that the focus of the input field will be lost, which is not good if you want to input more than just one digit, or tab between input fields.
What would be the most elegant way to solve this?
I would handle this by setting model.set({qty: _qty}, {silent: true}) and then updating the non-input fields with this.$.
As an alternative to the silent treatment: rather than listening for change events, listen for change:qty and change:sellPrice and have a method that updates just the HTML that needs updating within this.$, rather than re-rendering the DOM object and breaking your focus.
Either way, your comment about "selective updating" on the fiddle is certainly the right way to go.
(this.$ is a backbone hack to jQuery that restricts all selectors to search only within the DOM of the View's element. The element doesn't even need an ID or class; it just needs to exist and the View maintains a handle to it. It's incredibly useful.)
i built a plugin for backbone called Backbone.ModelBinding that may be able to help in this situation. my plugin allows you to update portions of a view with data from a model, when the model changes.
i've forked / updated your fiddle to show it in action: http://jsfiddle.net/derickbailey/FEcyF/6/
i removed the binding to the model change. i've also added id attributes to the inputs of the form to facilitate the plugin (the attribute that the plugin uses is configurable, though). and lastly, i've added a data-bind attribute to the sell price total td.
you can get the plugin here: http://github.com/derickbailey/backbone.modelbinding/
hope that helps
FWIW: my plugin is an automated version of what Elf is suggesting. I've written code exactly like he is describing, numerous times, which is where the plugin came from. I just got tired of writing that code by hand :)