I would like to add dynamically some materialize chips.
$('.chips-initial').material_chip({
data: [{
tag: 'Apple'
}, {
tag: 'Microsoft'
}, {
tag: 'Google'
}]
});
Like above but the values I want to give are dynamic. How can I create an data object like above to pass it as parameter? Thank you in advance
I would like to add dynamically some materialize chips.
$('.chips-initial').material_chip({
data: [{
tag: 'Apple'
}, {
tag: 'Microsoft'
}, {
tag: 'Google'
}]
});
Like above but the values I want to give are dynamic. How can I create an data object like above to pass it as parameter? Thank you in advance
Share Improve this question asked Sep 8, 2016 at 16:09 gf.geegf.gee 411 silver badge3 bronze badges 1- I would suspect that you could create your own array of objects and pass that variable array instead of hard coding it. – Twisty Commented Sep 9, 2016 at 18:53
3 Answers
Reset to default 4Basically what happens here is when the page loads it populates the text string values found in metaTags that were inserted into a hidden field from the database. The for loop iterates into the necessary chips-initial.
var tagsMeta = [];
//alert(tagsMeta);
var tagsString = document.getElementById('metaTags').value;
//alert(tagsString);
var tagsArray = tagsString.split(',');
for(i=0; i < tagsArray.length; i++) {
tagsMeta.push({tag: tagsArray[i]});
}
$('.chips-initial').material_chip({
data: tagsMeta
});
As I mented, you could create your own array of values and pass that to data
. This might look like:
var myData = [
{
tag: 'iPhone'
}, {
tag: 'Windows Phone'
}, {
tag: 'Android Phone'
}
];
$('.chips-initial').material_chip({
data: myData
});
Wokring Example: https://jsfiddle/Twisty/en6r0ucb/
I found solution
var authData = [];
var tag = {};
tag["tag"] = yourString;
authData.push(tag);
$('.chips-initial').material_chip({
data: authData
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745130642a4612955.html
评论列表(0条)