I have a show view that displays the selected item from a list. Then when i click on the edit button it displays the edit view via {{#if isEditing}}
When I click another item in the list the display view changes to the new selected item but stays in the isEditing state.
How can I change the isEditing state of a view from another view ?
I have done this at the moment with a FocusOut function that sets isEditing to false but I have 2 text fields in this view and so when I click into the other text field it triggers the focusOut function as well.
This must be simple but can't seem to figure it out!
A view in an Ember.js is used for to handle user events and also creates the re-usable component. The UI will be developed by using the views. The below figure shows how event handling occurs −
Handlebars templates in Ember.js are powerful and can be rendered by using Ember.View and inserted into DOM. You can set templateName property of a view to indicate which template to use.
When user clicks on the event the view turns a primitive event (a click) into a semantic event ( Event Handling) and transferred to the Ember.Route for to get the event action. Handlebars templates in Ember.js are powerful and can be rendered by using Ember.View and inserted into DOM.
A view is represented by a single DOM element on the page. You can change what kind of element is created by changing the tagName property. You can also specify which class names are applied to the view by setting its classNames property to an array of strings:
Nice question. I think you need to do something a little more complicated than a simple binding to drive the content of the App.SelectedItemView
. I would try another computed property instead:
App.SelectedItemView = Ember.View.extend({
isEditing: false,
content: function() {
var selectedItem = App.SelectedItemController.get('content');
this.set('editingItem', false);
return selectedItem;
}.property('App.SelectedItemController.content'),
});
The trick about computed properties is that you can accomplish the same thing as a simple binding, but you can also add custom code to execute when the observed value changes (like conditionally setting editingItem
to null
in this case). The downside to a computed property is that it's a little more complicated to do a two-way binding (e.g. in this case to set App.SelectedItemController.content
whenever App.SelectedItemView.content
changes)--but it sounds like you don't need to do that anyway.
How can i change the isEditing state of a view from another view ?
I don't think this is really want you want to do. In the click event for the item you are probably changing the content
property of the controller. You want isEditing
to be false whenever the content
changes.
You can set up an observer to handle this:
App.SelectedItemView = Ember.View.extend(
{
isEditing: false,
contentBinding: 'App.SelectedItemController.content',
contentChanged: function ()
{
this.set('isEditing', false);
}.observes("content")
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With