组芯片数据最初从数据库中Materialise的CSS

问题描述:

我在我的数据库中分隔字符串“”像这样组芯片数据最初从数据库中Materialise的CSS

"a","b","c","s" 

,所以我想通过一个在物质化的CSS追加此字符串值一个

<div class="chips chips-initial"></div> 

在这个div标签

这样

$('.chips-initial').material_chip({ 
data: [{ 
    tag: 'Apple', 
}, { 
    tag: 'Microsoft', 
}, { 
    tag: 'Google', 
}], }); 

但我不能像这样管理字符串数据作为Json对象数据。

我不确定您是否找到了上述问题的解决方案。这可能有助于其他人使用来自数据库/ JSON的Materialise CSS芯片数据。

我们需要编写自己的字符串数组对象功能,在使用Materialise的CSS芯片的数据

var UserPreferenceZoneData = []; 

function GetUserPreference(stringdata) 
{ 
    var userstate = stringdata; 
    var userstatearray = userstate.split(","); 
    //JSON Lookup data for your string 
    var ZoneJSONDataUse = {zonelist: { zone_id: a, zone_name: 'Apple'}, { zone_id: b, zone_name: 'Ball'}, } 
    $.each(userstatearray, function(i, userstate) { 
     $.each(ZoneJSONDataUse.zonelist, function(index, zone) { 
     if(userstatearray[i]==zone.zone_id) 
     { 
      var obj = { id: zone.zone_id, tag: zone.zone_name }; 
      UserPreferenceZoneData.push(obj); 
     } 
     }); 
    }); 
} 

//Call User Preference 
var stringdata = "a,b,c,s"; // Pass your string data from database/JSON here 
GetUserPreference(stringdata); 

//Now chips tag generated on your chip element 
    $('.chips-initial').material_chip({ 
    data: UserPreferenceZoneData, 
    }); 
+0

谢谢你的答案,但我发现解决方案:) –