select2读后台数据回写显示不出来问题

错误截图

在这里插入图片描述
错误描述:非select2插件元素可正常回写,但select2插件干涉的显示框无法正常回写。

错误原因分析

分析:直接请求数据库返回结果如图
在这里插入图片描述
我们冲数据库读到的信息为字符串,而select2插件的配置是要一个json对象

解决方案

在controller层–>angularJs
处理返回数据结果,将其解析为Json对象

	//查询实体 
	$scope.findOne=function(id){				
		typeTemplateService.findOne(id).success(
			function(response){
				$scope.entity= response;
				//处理返回数据结果,解析为Json对象
				$scope.entity.customAttributeItems = JSON.parse(response.customAttributeItems)
				$scope.entity.specIds = JSON.parse(response.specIds)
				$scope.entity.brandIds = JSON.parse(response.brandIds)
			}
		);				
	}

问题解除后效果展示

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43231352/article/details/83755599