optimize the js code for showing tree list of products