0

I want to take json data and put it in my template. Actually i am using angular2react package to use angularjs code in my reactjs project

This is my component: const component= { template :<input type=\"number\" ng-model=\"size\" name=\"size\" min=\"0\" max=\"10\" integer />{{size}}<br />

}

export default component;

This is the json data:

"modelView": { "components": [ { "resource": "virtualDomains.StudentCourseList", "name": "Testingpageresource", "type": "resource", "staticData": [] }, { "components": [ { "allowDelete": false, "components": [ { "readonly": false, "name": "Testingpageblock_grid_text", "model": "SCBCRSE_CRSE_NUMB", "label": "Testingpageblock_grid_text", "loadInitially": true, "type": "text", "parameters": {}, "validation": {}, "required": false }, { "readonly": false, "name": "Testingpageblock_grid_child_2", "model": "SCBCRSE_EFF_TERM", "label": "Testingpageblock_grid_child_2", "loadInitially": true, "type": "text", "parameters": {}, "validation": {}, "required": false } ], "onSave": "alert(\"Something\");", "onError": "{{size}}
", "allowNew": true, "pageSize": 5, "loadInitially": true, "type": "grid", "name": "Testingpageblock_grid", "allowModify": true, "model": "Testingpageresource", "allowReload": true, "parameters": {} }

I need the onError data and need to put it in the template to be able to use for angular2react

New contributor
Nishant Verma is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • I got the solution for this. But if Someone finds a solution please respond because it can be better than mine – Nishant Verma Feb 11 at 9:25
0

It's good to start with what version of EE you're working with so we all know.

I'm not familiar with the angularjs package you're using, but I know how to get tag data into your templates.

First you need an add-on that is installed where you can work with your json object in php and parse into tagdata. (if you don't have this there's a whole process that I can go over with you)

Assuming the class for this method is named My_class, you would have a method within it that looks something like this:

function get_on_error_tagdata ( $json ) {
    $object = json_decode( $json, true );
    $variables = array();
    foreach ( $object['onError'] as $key => $value ) {
        $variables[$key] = $value
    }
    return ee()->TMPL->parse_variables_row( ee()->TMPL->tagdata, $variables );
}

Now, I'm not sure how you're getting your $json object in the first place, but assuming you already have it you'll have to work with it to make sure it's parsed into the $variables array properly, but once you have that you'll be able to access those values on the frontend like this:

{exp:my_class:get_on_error_tagdata}
    {allowNew}
    {pageSize}
    {loadInitially}
    {type}
    {etc}
{/exp:my_class:get_on_error_tagdata}

You can also pass values to your class using that tag as well by adding my_value='{whatever data you want the class to have}' inside the opening tag and inside of your method add $value = ee()->TMPL->fetch_param('my_value');

I hope this helps.

  • Thanks a lot, I will try it out myself – Nishant Verma Feb 14 at 4:38

Your Answer

Nishant Verma is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.