A new hydrogel based on glucose-appended Schiff base derivative has been employed as the template to synthesize CdS and NiS nanostructures with different morphologies. The FT-IR and UV-vis results revealed that H-bonding and pi-pi interaction played important roles in the formation of original hydrogel fibers. The study of mineralization mechanism suggested that the inorganic ions were firstly adsorbed at the surface of the hydrogel fibers due to the hydrophilic affinity with the hydrophilic glucose groups. With the penetration of H2S gas, the preformed CdS or NiS nanoparticles on the surface of the fibers acted as the growing points for the continuous growth. And the different adsorption abilities of the metal ions at the hydrogel fibers resulted in the formation of CdS nano-necklaces and NiS nanotubes.