# Observable problem.

**URL:** <https://forums.fusetools.com/t/observable-problem/4764>\
**Category:** How-to Discussions\
**Created:** [June 11, 2017, 6:21pm UTC](https://forums.fusetools.com/t/observable-problem/4764 "2017-06-11T18:21:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JiwonJeon](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@JiwonJeon](https://forums.fusetools.com/u/JiwonJeon)\
**Post date:** [June 11, 2017, 6:21pm UTC](https://forums.fusetools.com/t/observable-problem/4764/1 "2017-06-11T18:21:31Z")

</div>

```
	var Observable=require("FuseJS/Observable");
	fruits = Observable(
	    { name: "Apple" , color: "red" },
	    { name: "Lemon" , color: "yellow" },
	    { name: "Pear" , color: "green" },
	    { name: "Banana", color: "yellow" });

	goodFruits = fruits.where({color: "yellow"});

	goodFruits = fruits.where(function(e){ 
	    return e.color === "yellow";
	});
	console.log(""+goodFruits.name);

```

This code result in ‘undefined’  
why??  
how can i get the value “yellow” from the goodFruits?

---

<div class="post-metadata">

**Author:** ![superpikar](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/superpikar/32/442_2.png) [@superpikar](https://forums.fusetools.com/u/superpikar)\
**Post date:** [June 12, 2017, 9:27am UTC](https://forums.fusetools.com/t/observable-problem/4764/2 "2017-06-12T09:27:49Z")

</div>

As mentioned in the [Fuse](https://www.fusetools.com/docs/fusejs/observable#subscribing-to-changes-in-observables)

> A really important thing to understand about Observables is that they need at least one subscriber before they start propagating data.

You can read the [docs](https://www.fusetools.com/docs/fusejs/observable#subscribing-to-changes-in-observables) for more detail information.

---

<div class="post-metadata">

**Author:** ![JiwonJeon](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@JiwonJeon](https://forums.fusetools.com/u/JiwonJeon)\
**Post date:** [June 12, 2017, 10:24am UTC](https://forums.fusetools.com/t/observable-problem/4764/3 "2017-06-12T10:24:14Z")

</div>

I tried databinding to ux attribute. But it still not work.  
console results in goodFruits:(observable).  
There is nothing to put in the goodFruits.

```
<App>
<JavaScript>

	var Observable=require("FuseJS/Observable");
	var fruits = Observable(
	    { name: "Apple" , color: "red" },
	    { name: "Lemon" , color: "yellow" },
	    { name: "Pear" , color: "green" },
	    { name: "Banana", color: "yellow" });

	var goodFruits = fruits.where(function(e){ 
	    return e.color === "yellow";
	}); 

	console.log("goodFruits:"+goodFruits); 

	module.exports={ goodFruits: goodFruits, fruits: fruits}

</JavaScript>
   <!--class-->
<Button ux:Class="myBtn">
</Button>
<!-- -->
<!-- EdgeNavigator-->
<EdgeNavigator>
	<!-- MainView -->
	<Button Height="10%" Text="Show Edge">
		<Clicked>
			<NavigateToggle Target="sidebar" />
		</Clicked>
	</Button>
	<Text Value="goodFruits:{goodFruits}"/>
	<!-- MainView -->
	<!-- Edge -->
	<Grid Width="100%" ux:Name="sidebar" Background="#fff" Edge="Left">
		
		<Shadow ux:Name="shadow" Angle="180" Distance="8" Size="16" Color="#0000" />
		<ActivatingAnimation>
			<Change shadow.Color="#0004" />
		</ActivatingAnimation>
		<Each Items="{fruits}">
			<Text Value="name:{name}"/>
			<Text Value="color:{color}"/>
		</Each>
	</Grid>
	<!-- Edge -->
</EdgeNavigator>
<!-- EdgeNavigator-->
</App>
```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 12, 2017, 10:36am UTC](https://forums.fusetools.com/t/observable-problem/4764/4 "2017-06-12T10:36:05Z")

</div>

Hi ,

it’s extremely confusing looking at what you’re trying to do. Let’s break it apart.

One:

```auto
var goodFruits = fruits.where(function(e){ 
    return e.color === "yellow";
});
console.log("goodFruits:"+goodFruits);

```

You can not to that. `goodFruits` is the resulting observable of a _reactive_ operation, meaning that you _can not_ access it in imperative style, like you do with the `console.log()`. The variable simply is not populated there yet.

Next, you data-bind to it like so:

```auto
<Text Value="goodFruits:{goodFruits}"/>

```

how does that even make sense? `goodFruits` is expected to be _a list of objects_, so you would use it with an `Each`.

And finally, if you have so many questions about working with Observables, would you mind to first spend some time reading the [Observable docs](https://www.fusetools.com/docs/fusejs/observable)?

---

<div class="post-metadata">

**Author:** ![superpikar](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/superpikar/32/442_2.png) [@superpikar](https://forums.fusetools.com/u/superpikar)\
**Post date:** [June 12, 2017, 4:22pm UTC](https://forums.fusetools.com/t/observable-problem/4764/5 "2017-06-12T16:22:47Z")

</div>

As @Uldis explained above, bind the `goodFruits` into `<Each >`, then you can use Observable API `toArray()` to print the values of observable.

And since Fusetools uses V8 Javascript engine, it cannot prints array or object, so you need `JSON.stringify()` function to print your variable value.

Hope it helps.

```auto
<App>
	<JavaScript>
		var Observable=require("FuseJS/Observable");
	    var fruits = Observable(
	        { name: "Apple" , color: "red" },
	        { name: "Lemon" , color: "yellow" },
	        { name: "Pear" , color: "green" },
	        { name: "Banana", color: "yellow" });

	    var goodFruits = fruits.where({color: "yellow"});

	    goodFruits.onValueChanged(module, function(item) {
			//do something
	    	console.log(JSON.stringify(goodFruits.toArray()));  
		});
	    
	    module.exports = {
	    	goodFruits: goodFruits, 
	    	fruits: fruits
	    };
	</JavaScript>
	<StackPanel>
		<Each Items="{goodFruits}">
			<Text Value="{name}" />	
		</Each>
	</StackPanel>
</App>

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 12, 2017, 4:26pm UTC](https://forums.fusetools.com/t/observable-problem/4764/6 "2017-06-12T16:26:58Z")

</div>

Right. Except you should not use `.onValueChanged` on a list Observable, since it will only fire when the first element on that list changes.
