I use the following sample to add a shapefile to FeatureLayer but attributes won't carry over.
ArcGIS API for JavaScript Sandbox
Any idea how I can retain all attributes from shapefile?
You just need to specify the Feature Layers fields and outFields properties in that sample.
<SPAN class="keyword token">var</SPAN> featureLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> popupTemplate<SPAN class="punctuation token">:</SPAN> popupTemplate<SPAN class="punctuation token">,</SPAN> objectIdField<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"FID"</SPAN><SPAN class="punctuation token">,</SPAN> source<SPAN class="punctuation token">:</SPAN> graphics<SPAN class="punctuation token">,</SPAN> outFields<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">:</SPAN> layer<SPAN class="punctuation token">.</SPAN>layerDefinition<SPAN class="punctuation token">.</SPAN>fields <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks! adding "fields: layer.layerDefinition.fields" solved the issue.
Hi Xiaowen,
Do you have screenshots or code you can share? Off the top of my head I would think that perhaps your shapefile is not a zip folder or your zip folder does not have all the necessary files in it to draw it with attributes.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.