富文本编辑器之easyui的tree的动态数据(一)
来源:互联网 发布:大唐软件官网 编辑:程序博客网 时间:2024/06/05 20:04
第一步 引入富文本编辑器的js文件
<link href="/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
第二步 编写form表单
<div style="padding:10px 10px 10px 10px">
<form id="itemAddForm" class="itemForm" method="post"><table cellpadding="5">
<tr>
<td>商品类目:</td>
<td>
<!-- selectItemCat这是个事件绑定的class -->
<a href="javascript:void(0)" class="easyui-linkbutton selectItemCat">选择类目</a>
<input type="hidden" name="cid" style="width: 280px;"></input>
</td>
</tr>
<tr>
<td>商品标题:</td>
<td><input class="easyui-textbox" type="text" name="title" data-options="required:true" style="width: 280px;"></input></td>
</tr>
<tr>
<td>商品卖点:</td>
<td><input class="easyui-textbox" name="sellPoint" data-options="multiline:true,validType:'length[0,150]'" style="height:60px;width: 280px;"></input></td>
</tr>
<tr>
<td>商品价格:</td>
<td><input class="easyui-numberbox" type="text" name="priceView" data-options="min:1,max:99999999,precision:2,required:true" />
<input type="hidden" name="price"/>
</td>
</tr>
<tr>
<td>库存数量:</td>
<td><input class="easyui-numberbox" type="text" name="num" data-options="min:1,max:99999999,precision:0,required:true" /></td>
</tr>
<tr>
<td>条形码:</td>
<td>
<input class="easyui-textbox" type="text" name="barcode" data-options="validType:'length[1,30]'" />
</td>
</tr>
<tr>
<td>商品图片:</td>
<td>
<a href="javascript:void(0)" class="easyui-linkbutton picFileUpload">上传图片</a>
<input type="hidden" name="image"/>
</td>
</tr>
<tr>
<td>商品描述:</td>
<td>
<textarea style="width:800px;height:300px;visibility:hidden;" name="desc"></textarea>
</td>
</tr>
<tr class="params hide">
<td>商品规格:</td>
<td>
</td>
</tr>
</table>
<input type="hidden" name="itemParams"/>
</form>
<div style="padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
</div>
</div>
第三步 编写selectItemCat的js代码
init : function(data){
// 初始化选择类目组件
this.initItemCat(data);
}
// 初始化选择类目组件
initItemCat : function(data){
$(".selectItemCat").each(function(i,e){
var _ele = $(e);
if(data && data.cid){
_ele.after("<span style='margin-left:10px;'>"+data.cid+"</span>");
}else{
_ele.after("<span style='margin-left:10px;'></span>");
}
_ele.unbind('click').click(function(){
$("<div>").css({padding:"5px"}).html("<ul>")
.window({
width:'500',
height:"450",
modal:true,
closed:true,
iconCls:'icon-save',
title:'选择类目',
onOpen : function(){
var _win = this;
$("ul",_win).tree({
url:'/item/cat/list',
animate:true,
onClick : function(node){
if($(this).tree("isLeaf",node.target)){
// 填写到cid中
_ele.parent().find("[name=cid]").val(node.id);
_ele.next().text(node.text).attr("cid",node.id);
$(_win).window('close');
if(data && data.fun){
data.fun.call(this,node);
}
}
}
});
},
------------------------------------------------前台编写完毕------------------------------------------------------------------
poji类
ItemCat
public class ItemCat implements Serializable{
private Long id;
private Long parentId;
private String name;
private Integer status;
private Integer sortOrder;
private Boolean isParent;
private Date created;
private Date updated;
}
前台传递的参数的包装vo类
public class EasyUITreeNode implements Serializable{
private long id; //父节点id
private String text; //内容
private String state; //子节点状态,closed :表示还有子节点,open表示没有子节点
}
数据库样式
Controller
@Controller
public class TreeController {
@Autowired
private TreeService treeService;
@RequestMapping("/item/cat/list")
@ResponseBody
public List<EasyUITreeNode> findItemCatList(@RequestParam(value="id",defaultValue="0") Long parentId){
List<EasyUITreeNode> results = treeService.getItemCatList(parentId);
return results;
}
}
service
public interface TreeService {
List<EasyUITreeNode> getItemCatList(Long parentId);
}
service实现类
@Service
@Transactional
public class TreeServiceImpl implements TreeService {
@Autowired
private TreeMapper treeMapper;
@Override
public List<EasyUITreeNode> getItemCatList(Long parentId) {
//通过父id查询出所有Itemcat
List<ItemCat> itemCats = treeMapper.getItemCatList(parentId);
List<EasyUITreeNode> easyUITreeNodes = new ArrayList<>();
for (ItemCat itemCat : itemCats) {
EasyUITreeNode node = new EasyUITreeNode();
node.setId(itemCat.getId());
node.setText(itemCat.getName());
node.setState(itemCat.getIsParent()?"closed":"open");
easyUITreeNodes.add(node);
}
return easyUITreeNodes;
}
}
mapper接口
public interface TreeMapper {
List<ItemCat> getItemCatList(Long parentId);
}
mapper的映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.taotao.mapper.tree.TreeMapper">
<select id="getItemCatList" parameterType="Long" resultType="com.taotao.pojo.item.ItemCat">
select * from itemCat
<where>
parentId=#{id}
</where>
</select>
</mapper>
-----------------------------------------------------------------------------(完)-----------------------------------------------------------------------
- 富文本编辑器之easyui的tree的动态数据(一)
- 基于easyui的富文本编辑器的实现
- 【easyui】kindeditor富文本(html编辑器)的使用
- 我的富文本编辑器
- 富文本编辑器的使用
- 富文本编辑器的使用
- 常用的富文本编辑器
- 富文本编辑器的使用
- 富文本编辑器的制作
- 富文本编辑器的使用
- 富文本编辑器的用法
- 富文本编辑器的使用
- summernote富文本编辑器的基本使用(一)
- draft.js--富文本编辑器框架的实践(一)
- iOS富文本编辑器之更"优雅的"实现方法
- Django之富文本编辑器的使用,超级简单~
- 关于EasyUI与富文本编辑器结合使用的问题(kindueditor与uueditor)
- 富文本编辑器的基本原理与实践
- MYSQL动态给VIEW变量,创建动态VIEW
- win _TOMCAT集群配置
- 为什么你要建立SEO博客
- linux中tomcat的安装和部署
- Thumbnailator生成缩略图
- 富文本编辑器之easyui的tree的动态数据(一)
- okhttp3相关封装配置(三):Callback封装,添加onStart()和onFinish()回调方法
- 取当前路径方法
- JS对象数据属性 && Object.defineProperty函数
- mysql 判断两个时间差 然后赋值 使用 case when
- python 实现得到当前时间偏移day天后的日期
- Unity AudioSourceManager (一行代码播放指定BGM)
- textview滚动
- 野指针 空指针