Template is not refreshed after data changes


#1

Template is not refreshed in below case, I fetch a list of Student where Student has name, age, address properties.
I render ‘Student List Template’ in left side and render ‘Edit Student Detail Template’ in right side.
‘Edit Student Detail Template’ got updated after I click any list item of ‘Student List Template’.
But the issue is if there are two Student object have same name, age and address(_id are different since it is generated from mongoldb). ‘Edit Student Detail Template’ won’t got refreshed even if you changed input field value before click list item.
attach code snippet below:

 <template name="layout">
	<div class="container">
		<header>welcome</header>
		{{> yield}}
	</div>
</template>
<template name="main">
	<main>
		<div>
			{{> stuList}}			
		</div>
		<div>{{> stuDetails}}</div>
	</main>
</template>
<template name="stuList">
	<ul class="stuList">
		{{#each stuList}}
			{{> oneStu}}
		{{/each}}
	</ul>
</template>

<template name="oneStu">
	<li class="oneStu"><a id="{{_id}}" class="oneStu" href="#">{{ name }}</a></li>
</template>

<template name="stuDetails">
	<ul>
		<li>type: {{ stuDetails.type}}</li>
		<li>question: <input type="text" value="{{ stuDetails.name}}" class="name" ></li>
		<li>question: <input type="text" value="{{ stuDetails.address}}" class="address" ></li>
	</ul>
</template>

StuList = new Mongo.Collection('stuList');

Meteor.subscribe('stuListPreloaded');

Template.stuList.helpers({
	stuList : function(){
		Session.set('stuDetails', StuList.findOne());
		return StuList.find();
	}
});
Template.stuDetails.helpers({
	stuDetails: function(){
		return Session.get('stuDetails');
	}
});

Template.main.events({
  	'click .oneStu': function(e){
  		e.preventDefault();
  		
  		var stu = StuList.findOne(this._id);
  		Session.set('stuDetails', stu);
  	}
});

#2

I think it would be good to use _id to differentiate the students, since _id is unique. Wont be problematic later on.


#3

there is _id since it is generated automatically after stored to mongo.


#4

Great, then duplicated student name, address is not that problem. Your issue with not rendered might be other issue.


#5

attached code here :sweat_smile:


#6

I think you need to proper separate your code and slowly check which part was not behaving as you expected. If you could create a working test repo. We are better diagnose the issue.