Guest User

dynamically add component attributes

a guest
Jan 29th, 2015
191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function(){
  2. $("[name=type_id]").on("change", function(){
  3. var typeId = $(this).val();
  4.  
  5. $.get('${ contextPath }/api/v1/attributes?type_id=' + typeId, function (response) {
  6. console.dir(response);
  7.  
  8. for (var i = 0 ; i < response.length; i++) {
  9. console.log(response[i]);
  10. $(".attributes").add( "label" ).addClass( "col-attribute col-sm-2 control-label" );
  11. $(".attributes").add( "div" ).addClass( "col-sm-8" );
  12. $(".attributes").add( "input" )
  13. .addClass("form-control")
  14. .attr("name","response[i].name")
  15. .attr("id","response[i].id}");
  16. }
  17.  
  18. })
  19. .fail(function () {
  20.  
  21. })
  22. .always(function () {
  23.  
  24. });
  25. });
  26. });
RAW Paste Data