View API:
Start a simple clock task, perform an update once per second
div var task = {
< Span class= "PLN" > Run: function () { ext. ( ' clock ' new date (). Span class= "PLN" >format ( ' g:i:s A ' Span class= "pun" >}, Interval: 1000 //1 sec
}
Ext.TaskManager.start (Task);
1,extjs how to operate once in a certain time
You can see that the task is a Var, which is done once by setting the interval interval
2, realize the function:
View Layer Code:
8Ext.define (' ExtApp.view.StudentMonitor ' , {9Extend: ' Ext.grid.Panel ' ,TenID: ' Studentmonitorgrid ' , OneXtype: ' Studentmonitor ' , AStore: ' Studentmonitor ' , -Draggable:false,//set to False to disable drag-and-drop to change the column order, -Columnlines:true,//add a column's border style the viewconfig: { -Striperows:true //true to change the color for interlaced - }, - Tbar: [{ +Xtype: ' Form ', -Width: ' 100% ', +ID: ' Formmonitor ', A items: [{ atXtype: ' Container ', -Padding:5, -Flex:2, - layout: { -Type: ' Hbox ' - }, in items: [{ -Xtype: ' button ', toID: ' Btnonmonitor ', +Text: ' Open Student monitor ' - },{ theXtype: ' button ', *ID: ' Btnoffmonitor ', $Text: ' Turn off student monitoring 'Panax Notoginseng },{ -Padding:5, theXtype: ' Container ', +Flex:1, AAnchor: ' 100% ', the layout:{ +Type: ' Hbox ', -Pack: ' End ' $ }, $ items:[{ -Xtype: ' button ', -ID: ' Btnemptymonitor ', theText: ' Empty All ' - }]Wuyi }] the }] - }], Wu columns: [ - //{xtype: ' Rownumberer ', text: ' Serial number ', flex:1, align: ' center '}, About{text: ' Account ID ', flex:1, align: ' center ', dataindex: ' Usercode '}, ${text: ' User name ', flex:1, align: ' center ', dataindex: ' UserName '}, -{text: ' Grade ', flex:1, align: ' center ', dataindex: ' Gradename '}, -{text: ' Time ', Flex:2, align: ' center ', Dataindex: ' Times ' }, -{header: "Test Record", Align: "center", flex:2, ARendererfunction(value) { + return' <font size= ' 3 "color=" Red "> The classmate has not operated the screen for 5 minutes </font> '; the } - }, ${xtype: ' Actioncolumn ',//This is where you put the button. theHeader: ' Operation ' , theWidth:50 , theFlex:1 , theAlign: ' center ', - items: [{ inIcon: ' Images/user_delete.png ',//Delete Icon theToolTip: ' Delete account ' , theHandler:function(grid, RowIndex, Colindex) { About Console.log (rowIndex); the varstore =Grid.getstore (); the Console.log (Store.getat (RowIndex)); the store.removeat (rowIndex); + grid.updatelayout (); - } the }]Bayi }], the dockeditems:[{ theXtype: ' Pagingtoolbar ', -Store: ' Studentmonitor ',//data used in the Gridpanel -Dock: ' Bottom ', theDisplayInfo:true the }] the the});
3, how do I delete a row of the store as a local grid?
Through the grid band function handler can be found RowIndex, through Store.removeat (RowIndex);
Controller Layer Code:
1Onmonitor:function(btn,event) {2 varGRID=EXT.GETCMP (' Studentmonitorgrid ');3 varStore= This. GetStore (' Studentmonitor ');4 varPagebar = Grid.down (' Pagingtoolbar '));5 Pagebar.movefirst ();6task={7Runfunction(){8 Ext.Ajax.request ({9URL: ' Getmessages.action ',TenCallbackfunction(options,success,response) { One Console.log (response); A Console.log (Response.responsetext); - Console.log (Ext.decode (Response.responsetext)); - Console.log (Ext.decode (response.responsetext). rows); the vardata =Ext.decode (response.responsetext). Rows; - for(varIinchdata) { - Console.log (Data[i]); - Store.add ({ + Usercode:data[i].usercode, - Username:data[i].username, + Time:data[i].time, A Gradename:data[i].gradename at }) - } - } - }) - }, -interval:1000 in }; - Ext.TaskManager.start (Task); to} ,
var task;
4,extjs in decode use
By printing out the response, you can see that what we need is responsetext, because the return is a Jason format string
We need to use decode, we can see Api:decode ( String json, Boolean safe): Object, incoming is a Jason, come out is an object
by printing Console.log (Ext.decode (Response.responsetext)); We found that the "Rows" and "results" were returned, and we got rows and returned an array that was taken to the value in the array by the for (var i-in data)
5,extjs How do I add a line to gird?
Store.add ()
Reference: http://blog.csdn.net/itlwc/article/details/7868626
var record = Store.getat (index);
Store.add (
New Myrecord ({
Name: ' LWC ',
Age:18
})
);
ExtJS timed operation