javascript - Materialize chips initialization - Stack Overflow

I would like to add dynamically some materialize chips.$('.chips-initial').material_chip({dat

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
Add a ment  | 

3 Answers 3

Reset to default 4

Basically 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

相关推荐

  • javascript - Materialize chips initialization - Stack Overflow

    I would like to add dynamically some materialize chips.$('.chips-initial').material_chip({dat

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信