1

I'm trying to render the array of text when I load the page:

'values': ['hello', 'world']

but it's giving me an error. In my formatoc.js , I have:

var props = {
    'name' : 'form',
    'timer' : 1500,
    'callback' : function(id, validity, value) {console.log(id, validity, value);},
    'values': ['hello', 'world'],
    'newParent' : new FormatOC.Parent({

        "one": {"__array__":"unique", "__type__":"string","__minimum__":1,"__maximum__":200,"__component__":"Input"}

    })

}

React.render(React.createElement(ParentComponent, props), document.getElementById('react-component'));

This is what I have in my Parent.jsx file:

define(['react', 'r_foc_node'], function(React, NodeComponent) {

var ParentComponent = React.createClass({

    getInitialState: function() {

        if(!this.props.newParent) {
            throw "ParentComponent requires newParent property";
        }

        return {
            "values": {}
        }
    },

    recursive : function(level) {

        that = this;

        console.log(level);

        for (keys in level) {
            console.log("This is a key: ", keys);

            if ((typeof level[keys]) === "object") {
                if (level[keys].constructor.name === "Parent") {
                    console.log('I am a parent');
                    level = level[keys].details();
                    //console.log(level[keys].get([key_list[0]]));
                    this.recursive(level);
                    //console.log(level[keys].keys());
                } else {
                    console.log('I am a node');
                    //console.log(level[keys]);
                };

            };

        }
    },

    childChange: function(name, valid, value) {

        this.state.values[name] = value;
        this.setState(this.state);

        console.log(name,value);


        // Call parent callback
        this.props.callback(
            this.props.name,
            this.props.newParent.valid(this.state.values),
            this.state.values
        );
    },

    render: function() {
        var that = this;

        var level = this.props;

        return (
            <div id = "form">
            {level.newParent.keys().map(function(k) {
                return (
                    <div>
                    {(level.newParent.get(k).constructor.name === "Parent") ?
                    <ParentComponent
                        name={k}
                        key={k}
                        timer={that.props.timer}
                        callback={that.childChange}
                        values={that.props.values[k]}
                        newParent={that.props.newParent.get(k)}
                    />
                    :
                    <NodeComponent
                        name={k}
                        key={that.props.name + '.' + k}
                        timer={that.props.timer}
                        callback={that.childChange}
                        values={that.props.values[k]}
                        newNode={that.props.newParent.get(k)}
                    />
                    }
                    </div>
                )
            })
            }
            </div>
        )
    }

I'm not sure if the error is because of the way I'm trying to access the array values? But I can't seem to get the words hello and world to be rendered.

1 Answer 1

2

You are using: level.newParent.keys().map(function(k) {...
this should be: level.values.map(function(k) {...

Sign up to request clarification or add additional context in comments.

10 Comments

It gave me an error saying that Uncaught TypeError: level.values.keys.map is not a function. Should 'values' be in newParent?
Than you are not passing the props to Parent.jsx
If any it should be level.values.map(...). Arrays don't have a key property.
Oh that makes sense. Inside my return() in the Parent.jsx, is it correct for it to be values={that.props.values[0]}?
Where are you tring to render the values?
|

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.