Mechanistic design of functional materials from polyelectrolytes