select2讀後臺數據回寫顯示不出來問題
阿新 • • 發佈:2018-12-19
錯誤截圖
錯誤描述:非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) } ); }