Jamaica1000 0 Denunciar post Postado Março 24, 2010 boa tarde, to usando o flash builder 4 sou novato e tenho a seguinte dúvida: como inserir dados em um datagrid por campos de formulário, sem banco de dados, só por código mesmo? tenho tentado aqui, mas não to tendo resultado. segue abaixo meu código. <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; [Bindable] public var lista:ArrayCollection = new ArrayCollection([ {col1:"valor 1", col2:"valor 2", col3:"valor3"}, {col1:"valor 4", col2:"valor 5", col3:"valor6"} ]);//obrigatório usar [Bindable] e private para declar um ArrayColletion protected function button1_clickHandler(event:MouseEvent):void { //COLOCAR O COMANDO AQUI DENTRO } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <mx:DataGrid x="49" y="26" dataProvider="{lista}" id="grid"> <mx:columns> <mx:DataGridColumn headerText="Column 1" dataField="col1"/> <mx:DataGridColumn headerText="Column 2" dataField="col2"/> <mx:DataGridColumn headerText="Column 3" dataField="col3"/> </mx:columns> </mx:DataGrid> <mx:Form x="359" y="26"> <mx:FormItem label="col1"> <s:TextInput id="c1"/> </mx:FormItem> <mx:FormItem label="col2"> <s:TextInput id="c2"/> </mx:FormItem> <mx:FormItem label="col3"> <s:TextInput id="c3"/> </mx:FormItem> <s:Button label="enviar" click="button1_clickHandler(event)"/> </mx:Form> </s:Application> Compartilhar este post Link para o post Compartilhar em outros sites
Matheus Brito 12 Denunciar post Postado Março 25, 2010 Assim não uso flash builder ainda, continuo no bom e velho flex builder 3, mas é a mesma coisa vamos lá: [Bindable] private var moderadores:ArrayCollection = new ArrayCollection([ {nome:'kisuke',sobrenome:'Brito'}, {nome:'Eder',sobrenome:'Fortunato'}, {nome:'Carnerinho',sobrenome:'Whatever'} ]); //Se o tipo da minha var fosse Array eu poderia passar os valores pro array usando o push mas como é //ArrayCollection eu so posso usar o metodo addItem que so aceita obj, dai quando clico no bt chamo o metodo que //faz o processo. public function cadastrar(e:MouseEvent):void{ var obj:Object = new Object(); obj.nome = nome.text; obj.sobrenome = sobrenome.text; moderadores.addItem(obj); } <mx:DataGrid x="10" y="10" id="grid1" dataProvider="{moderadores}"> <mx:columns> <mx:DataGridColumn headerText="Nome" dataField="nome"/> <mx:DataGridColumn headerText="Sobrenome" dataField="sobrenome"/> </mx:columns> </mx:DataGrid> <mx:Form x="359" y="26"> <mx:FormItem label="Nome"> <mx:TextInput id="nome"/> </mx:FormItem> <mx:FormItem label="Sobrenome"> <mx:TextInput id="sobrenome"/> </mx:FormItem> </mx:Form> <mx:Button label="enviar" click="cadastrar(event)" x="359" y="130"/> Abs Compartilhar este post Link para o post Compartilhar em outros sites
Jamaica1000 0 Denunciar post Postado Março 25, 2010 manual eu consegui resolver, mas quando puxa do banco ele duplica os resultados, nao sei porque: tentei fazer parecido com o tutorial do site http://www.adobe.com/devnet/flex/testdrive/articles/2_modify_the_database.html, só que em vez de ficar abrindo um monte de states eu criei o datagrid e o form para adicionar numa tela só. meu codigo <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:employeeservice="services.employeeservice.*" xmlns:valueObjects="valueObjects.*"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.events.ResultEvent; protected function dataGrid_creationCompleteHandler(event:FlexEvent):void { getEmployeesResult.token = employeeService.getEmployees(); } protected function button_clickHandler(event:MouseEvent):void { lista.office = officeTextInput.text; lista.departmentid = parseInt(departmentidTextInput.text); lista.street = streetTextInput.text; lista.zipcode = zipcodeTextInput.text; lista.state = stateTextInput.text; lista.lastname = lastnameTextInput.text; lista.firstname = firstnameTextInput.text; lista.photofile = photofileTextInput.text; lista.city = cityTextInput.text; lista.title = titleTextInput.text; lista.officephone = officephoneTextInput.text; lista.email = emailTextInput.text; lista.cellphone = cellphoneTextInput.text; createEmployeeResult.token = employeeService.createEmployee(lista); } protected function createEmployeeResult_resultHandler(event:ResultEvent):void { ->O PROBLEMA TA AQUI lista.id = event.result as int; dataGrid.dataProvider.addItem(lista); } ]]> </fx:Script> <fx:Declarations> <s:CallResponder id="getEmployeesResult"/> <employeeservice:EmployeeService id="employeeService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/> <valueObjects:Lista id="lista"/> <s:CallResponder id="createEmployeeResult" result="createEmployeeResult_resultHandler(event)"/> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <mx:DataGrid x="41" y="38" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getEmployeesResult.lastResult}" height="221"> <mx:columns> <mx:DataGridColumn headerText="firstname" dataField="firstname"/> <mx:DataGridColumn headerText="lastname" dataField="lastname"/> <mx:DataGridColumn headerText="officephone" dataField="officephone"/> <mx:DataGridColumn headerText="email" dataField="email"/> </mx:columns> </mx:DataGrid> <mx:Form defaultButton="{button}" x="451" y="10"> <mx:FormItem label="Lastname"> <s:TextInput id="lastnameTextInput" text="{lista.lastname}"/> </mx:FormItem> <mx:FormItem label="Firstname"> <s:TextInput id="firstnameTextInput" text="{lista.firstname}"/> </mx:FormItem> <mx:FormItem label="Photofile"> <s:TextInput id="photofileTextInput" text="{lista.photofile}"/> </mx:FormItem> <mx:FormItem label="Title"> <s:TextInput id="titleTextInput" text="{lista.title}"/> </mx:FormItem> <mx:FormItem label="Officephone"> <s:TextInput id="officephoneTextInput" text="{lista.officephone}"/> </mx:FormItem> <mx:FormItem label="Email"> <s:TextInput id="emailTextInput" text="{lista.email}"/> </mx:FormItem> <mx:FormItem label="Cellphone"> <s:TextInput id="cellphoneTextInput" text="{lista.cellphone}"/> </mx:FormItem> <s:Button id="button" label="enviar" click="button_clickHandler(event)"/> </mx:Form> <mx:Form x="698" y="10"> <mx:FormItem label="Office"> <s:TextInput id="officeTextInput" text="{lista.office}"/> </mx:FormItem> <mx:FormItem label="Departmentid"> <s:TextInput id="departmentidTextInput" text="{lista.departmentid}"/> </mx:FormItem> <mx:FormItem label="Street"> <s:TextInput id="streetTextInput" text="{lista.street}"/> </mx:FormItem> <mx:FormItem label="Zipcode"> <s:TextInput id="zipcodeTextInput" text="{lista.zipcode}"/> </mx:FormItem> <mx:FormItem label="State"> <s:TextInput id="stateTextInput" text="{lista.state}"/> </mx:FormItem> <mx:FormItem label="City"> <s:TextInput id="cityTextInput" text="{lista.city}"/> </mx:FormItem> </mx:Form> </s:Application> Compartilhar este post Link para o post Compartilhar em outros sites
Jamaica1000 0 Denunciar post Postado Março 25, 2010 consegui resolver a solução é: protected function createEmployeeResult_resultHandler(event:ResultEvent):void { lista.id = event.result as int; dataGrid.dataProvider.addItem(lista); lista = new Lista(); // <- eu acrescentei essa linha e funcionou } Compartilhar este post Link para o post Compartilhar em outros sites