views:

96

answers:

2

Hi,

I wonder if any of you guys can help me with what I think is observing problem.

I have an element (svg to be more specific) that I want to update every time a value somewhere is changed.

I have variable: GetThreadTree().treeBoxObject.getFirstVisibleRow() that initially is 0. I want to run a function updateCanvas() every time value of GetThreadTree().treeBoxObject.getFirstVisibleRow() changes.

What I have is:

canvas.observe(GetThreadTree().treeBoxObject.getFirstVisibleRow(), "scroll", updateCanvas());

but it calls updateCanvas() only once, when it's called for the first time, and for some reason does not execute the code that is after it. I checked error console and nothing is there.

Any ideas?

+2  A: 

You logic is all in the wrong place. When you update your value what ever it is that needs to be done in one place by a function, something like treeBoxObject.IncrementRow() or similar.

Then you can have that function fire an event, like onTreeBoxRowIncremented. That event is what you listen out for, when that changes then you can do your check and update whatever you like.

Excuse the weird function names just trying to use what you have.

Pete Duncanson
A: 

One way of solving this problem is:

var registeredRow = 0;

function checkRow(){ var row = GetThreadTree().treeBoxObject.getFirstVisibleRow(); if (registeredRow != row) { registeredRow = row; updateCanvas(); } window.setTimeout(checkRow, 1); }

And before checkRow is called:

registeredRow = GetThreadTree().treeBoxObject.getFirstVisibleRow(); checkRow();

But it's not the most elegant solution but it works ;)

Artur