I have a view which contains some tabs (TabView).
Initially some tabs are disabled - they should only be enabled when a certain condition is met.
I'd like to implement it in the following way:
Create a TabViewModel which contains a boolean (observable?) property PersonSelected.
Create a TabViewStore
Bind the TabViewStore to the TabView
In my controller I would have an action method (e.g. onPersonSelected) which will should set the PersonSelected property to true.
What is the best way to bind the PersonSelected property to the View?
As my store would only contain on record, I feel that using the is a bit overkill. Can I do this without the store?
You can simply subscribe to the change event of the UI element (checkbox? in your case). Am I missing something?
Related
I have a list of objects displayed in a list. I get the object in this way
const elements = realm
.objects("Element").sorted("name", false);
Then I display those elements in a list and when I tap on an element of the list I open a new "scene" (I use react-native-router-flux) and send the object as props. Now when I update the object via Realm Studio I can't see the UI updates.
Is there anything like objects.addListener that I can use for listening to the single object changes? Or, How can I update the second view from the first (the one when I listen for changes at the collection)?
Thanks for the help.
Now it's possible to use listeners also on single objects.
Simply use
object.addListener((obect)=>{
// do updates
})
Is is possible to emit a synthetic event from a watched property in a way, that will not be checking the listeners (outside of Vue instance) on Vue instance initialization?
I have a situation in which I would like to watch for that synthetic event on a window object and perform a certain action on an object which does not exist at the time the Vue instance is created.
No matter how I try it to go about it I am getting an error:
Cannot read property 'set' of undefined
In my particular case, I want to 'move' the slider handle (I am using noUiSlider library) to a new position whenever the watched property changes - that is, the error message is specific, but my question refers to the generic case - is it possible? And if yes, how to do it?
For the listener to be able to operate on the slider, create the listener when you create the slider. There's no point to creating it before the slider exists.
Say I have a custom attribute in Aurelia and I put it on two different element.
If I have variable defined in the class called clickWhen: Date;
And if I set that in a method fired from the first element that has the custom attribute (ie `setupDoubleClick).
If a method is fired from the second element that has the custom attribute on it, is this.clickWhen set (because the first instance has set this.clickWhen) or is it still undefined.
(I hope it is the second.)
They are separate instances and they won't affect each other.
Is there a way to communicate from the parent viewmodel to a KnockoutJS component?
I have a component that contains a bootstrap modal dialog box, to search for customers and return a selected customer. At present, to make the dialog box appear, I pass an observable boolean from the viewmodel in the component's params attribute. To make the dialog appear I set this to true, which invokes the dialog box. I also pass a callback function in params to return the results.
Here is a fiddle demo which shows the concept: http://jsfiddle.net/Quango/5bxbsLt6/
Passing the observable boolean to invoke the dialog doesn't feel right, but it's the only working solution I have. The only other idea I had was to use ko-postbox to create a publish/subscribe function.
It feels like there should be a way to invoke actions, e.g. component.Show() ?
I think the answer here is that there isn't a better way. To communicate from a parent viewmodel to the component, pass an observable value, and then use that directly or subscribe to changes in the component.
I will put a suggestion on the Knockout github project to consider some form of interface.
I have a TextBlock and its Text property is bound to a ViewModel property. The binding is Oneway.
When I change the Text property of the Control from the xaml.cs the binding gets broken. If the binding is TwoWay I don't have this problem but the source property is updated too. Is it possible to have OneWay binding and change the target property value without braking the binding?
I suggest a workaround, like setting the Binding to TwoWay and ignore the update in the property. Something like this:
private string textValue;
public string TextValue
{
get { return textValue; }
set
{
:
}
}
Now the Property can no longer be set by the view.
Although no code is provided, this scenario typically occurs when you have bound a control to a view model and at a later stage your logic tries to update the value in the control programmatically.
You should not try to do this, that is define multiple sources of the value for a control. If you bind the control to a property on the view model, then to update the value in the control you should update the field in the view model.
If you were to set the value of a bound control programmatically at runtime so that it no longer matched the bound object value, when some other event causes the control binding to be re-evaluated, the value that you have provided programmatically would be overwritten again, you could easily end up with a scenario where the value you provided programmatically is never visible to the user.
In this scenario you should either:
Add a new property to the view model, bind this value to the control, then your program logic can set this value equal to the original property when the data is loaded, and updated when you need to
Not use bindings at all, always write to the control programatically that way you tightly control when the value is updated.
There is a workaround to this if you absolutely must have one. if you are using compiled bindings (x:Bind), then because the bindings are compiled it is possible to call SetValue on the bound dependency property at runtime and the previously compiled bindings will still be evaluated. However I advise against exploiting this because it makes your code a lot harder to follow and debug, when bindings are used, we tend not to look for code that directly addresses and sets control values.