1

I call the function tabulator() with these params.

$("#tableObj").tabulator("addRow", {id:1, Name:"John", Age:"20"}, true);

I want to pass the Array elements name dynamically, read from a Json ( '{id:1, Name:"John", Age:"20"}' ).

I mean that column names will change. Ex : {id:1, Company:"myComp", Address:"myaddress"}

How can I create theses objs from Strings or JSon text?

5
  • loop over the array and reference the objects? Commented Sep 6, 2016 at 18:06
  • I am not aware of a jQuery function tabulator(). Are you using a plugin? Commented Sep 6, 2016 at 18:06
  • Yes, It belongs to Dynamic Html Table. Commented Sep 6, 2016 at 18:10
  • 2
    var obj = JSON.parse(text) Commented Sep 6, 2016 at 18:18
  • $("#tableObj").tabulator("addRow", {json.Company:json["Company"]}, true); But do not work Commented Sep 6, 2016 at 18:28

1 Answer 1

1

You could use JSON.parse but be aware that id:1, Name:"John", Age:"20" is NOT valid JSON. The keys must be wrapped in quotes, otherwise it will produce an error.

var str = '{"id":1, "Name":"John", "Age":"20"}';
var obj = JSON.parse(str);

$("#tableObj").tabulator("addRow", obj, true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.