This is a migrated thread and some comments may be shown as answers.

Get element for binding

6 Answers 171 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Lala
Top achievements
Rank 1
Lala asked on 09 Sep 2015, 03:47 PM

Hi there

When binding enabled/disabled or visible/invisible I normally use callback functions to check the current state. Unfortunately the element itself is not given to these callback functions.

In my case, to determine the state of the element, I would need to check if the element, which called the callback function, is part of a disabled tab strip tab. But since there is no element given, I need to search for it in the DOM, which probably is not always reliable and could return multiple elements.

So my Questions:
Why is it, that no params are given to the callback function?
Can I change that?

Regards,
Patric

6 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 11 Sep 2015, 09:19 AM

Hello Patric,

 

the viewmodel functions are not "aware" of the elements bound to their results. Like you have noticed, there may be multiple elements bound to the same callbacks. 

 

Can you post a sample of what you are trying to achieve? We may be able to suggest an alternative method for its implementation. 

 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Lala
Top achievements
Rank 1
answered on 16 Sep 2015, 07:43 AM

Hello Petyo

In the end I created multiple callback functions. But still, I came across this scenario quite a few times since I'm using kendo. Since the project I'm working on is to complex I tried to create a simpler example of what I mean over here: http://dojo.telerik.com/oFUte

I can only guess, that one of the main reasons, why it's not intended to send the sender for the callback, that the callback is not observable aware unless I .get() a value from it inside the method itself.

Regards,
Patric

0
Petyo
Telerik team
answered on 18 Sep 2015, 07:41 AM

Hello Patric,

thank you for the clarification. What may help in that case would be the source binding approach. Please check this demo for what I mean.

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Lala
Top achievements
Rank 1
answered on 21 Sep 2015, 08:17 AM

Hello Petyo

Thank you for your answer. I didn't know, that the dataSource item would be given to the method. This could be a solution, but only, if the dataSource would be updated on every change, to redraw the elements and recall the method.

Regards,
Patric

0
Petyo
Telerik team
answered on 23 Sep 2015, 06:11 AM

Hello Patric,

 

please let me know if you need further assistance with this approach. 

 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 14 Mar 2016, 01:45 PM

I am trying to determine the element that is being bound as well. I am familiar with the datasource technique, but it still doesn't help me accomplish what i am trying to do. In this case I am building a wizard which is not well suited to being templatized. I have figured out how to hack around this and make a custom binding that sends in the element, but after 4 years of using kendo i think this is something that the framework would benefit from.

 

I have an example of what i am trying to accomplish. I don't want to litter my model with showHide functions. http://jsfiddle.net/grippstick/jodq7zug/

Tags
MVVM
Asked by
Lala
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Lala
Top achievements
Rank 1
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or