@ Author YHC
In this tutorial, we will create an rss reader using easyUI framework.
View DEMO
We will use the following plug-ins:
Layout: Create an application interface.
Datagrid: displays the rss feed list.
Tree: displays the feed channel.
Step 1: Create Layout
[Html]
<Body class = "easyui-layout">
<Div region = "north" border = "false" class = "rtitle">
JQuery EasyUI RSS Reader Demo
</Div>
<Div region = "west" title = "Channels Tree" split = "true" border = "false" style = "width: 200px; background: # EAFDFF;">
<Ul id = "t-channels" url = "data/channels. json"> </ul>
</Div>
<Div region = "center" border = "false">
<Div class = "easyui-layout" fit = "true">
<Div region = "north" split = "true" border = "false" style = "height: 200px">
<Table id = "dg"
Url = "get_feed.php" border = "false" rownumbers = "true"
Fit = "true" fitColumns = "true" singleSelect = "true">
<Thead>
<Tr>
<Th field = "title" width = "100"> Title </th>
& Lt; th field = "description" width = "200" & gt; Description & lt;/th & gt;
<Th field = "pubdate" width = "80"> Publish Date </th>
</Tr>
</Thead>
</Table>
</Div>
<Div region = "center" border = "false" style = "overflow: hidden">
<Iframe id = "cc" scrolling = "auto" frameborder = "0" style = "width: 100%; height: 100%"> </iframe>
</Div>
</Div>
</Div>
</Body>
<Body class = "easyui-layout">
<Div region = "north" border = "false" class = "rtitle">
JQuery EasyUI RSS Reader Demo
</Div>
<Div region = "west" title = "Channels Tree" split = "true" border = "false" style = "width: 200px; background: # EAFDFF;">
<Ul id = "t-channels" url = "data/channels. json"> </ul>
</Div>
<Div region = "center" border = "false">
<Div class = "easyui-layout" fit = "true">
<Div region = "north" split = "true" border = "false" style = "height: 200px">
<Table id = "dg"
Url = "get_feed.php" border = "false" rownumbers = "true"
Fit = "true" fitColumns = "true" singleSelect = "true">
<Thead>
<Tr>
<Th field = "title" width = "100"> Title </th>
& Lt; th field = "description" width = "200" & gt; Description & lt;/th & gt;
<Th field = "pubdate" width = "80"> Publish Date </th>
</Tr>
</Thead>
</Table>
</Div>
<Div region = "center" border = "false" style = "overflow: hidden">
<Iframe id = "cc" scrolling = "auto" frameborder = "0" style = "width: 100%; height: 100%"> </iframe>
</Div>
</Div>
</Div>
</Body> Step 2: The datagrid handles the event.
Here we want to handle some user-triggered events.
[Javascript]
$ ('# Dg'). datagrid ({
OnSelect: function (index, row ){
$ ('# CC'). attr ('src', row. link );
},
OnLoadSuccess: function (){
Var rows = $ (this). datagrid ('getrows ');
If (rows. length ){
$ (This). datagrid ('selectrow', 0 );
}
}
});
$ ('# Dg'). datagrid ({
OnSelect: function (index, row ){
$ ('# CC'). attr ('src', row. link );
},
OnLoadSuccess: function (){
Var rows = $ (this). datagrid ('getrows ');
If (rows. length ){
$ (This). datagrid ('selectrow', 0 );
}
}
}). This example uses the 'onselect' event to display the feed content and the 'onloadsuccess' event to select the first line.
Step 3: Process tree events
When the tree data has been loaded, We need to select the first leaf node, call the 'select' method to select the node, and use the 'onselect' event to obtain the selected node, so we can get the corresponding 'url' value.
In the end, we call the 'load' method of the datagrid to refresh the data in the feed list.
[Javascript]
$ ('# T-channels'). tree ({
OnSelect: function (node ){
Var url = node. attributes. url;
$ ('# Dg'). datagrid ('load ',{
Url: url
});
},
OnLoadSuccess: function (node, data ){
If (data. length ){
Var id = data [0]. children [0]. children [0]. id;
Var n = $ (this). tree ('Find ', id );
$ (This). tree ('select', n.tar get );
}
}
});
$ ('# T-channels'). tree ({
OnSelect: function (node ){
Var url = node. attributes. url;
$ ('# Dg'). datagrid ('load ',{
Url: url
});
},
OnLoadSuccess: function (node, data ){
If (data. length ){
Var id = data [0]. children [0]. children [0]. id;
Var n = $ (this). tree ('Find ', id );
$ (This). tree ('select', n.tar get );
}
}
}); Download EasyUI example:
Easyui-rssreader-demo.zip
Author: yhc13429826359