start to fix for arrays

This commit is contained in:
Jonathan Rainville 2018-10-17 17:13:36 -04:00 committed by Pascal Precht
parent c33818bd32
commit 88c610208c
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 9 additions and 4 deletions

View File

@ -68,7 +68,7 @@ class ScaffoldingReact {
throw new Error("file '" + filePath + "' already exists");
}
const templatePath = fs.embarkPath('lib/modules/scaffolding-react/templates/' + templateFilename);
const templatePath = utils.joinPath(__dirname, 'templates/' + templateFilename);
const source = fs.readFileSync(templatePath).toString();
const template = Handlebars.compile(source);

View File

@ -63,7 +63,7 @@ class {{capitalize name}}Form{{@index}} extends Component {
{{else}}
{{#each inputs}}
{{#ifarr type}}
input.{{trim name}} = input.{{trim name}}.split(',').map(x => trim(x.toString()));
input.{{trim name}} = input.{{trim name}}.split(',').map(x => x.toString().trim());
{{/ifarr}}
{{/each}}
@ -154,7 +154,7 @@ class {{capitalize name}}Form{{@index}} extends Component {
{
receipt &&
<Fragment>
<Alert bsStyle={receipt.status == "0x1" ? 'success' : 'danger'}>{receipt.status == "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash}</Alert>
<Alert bsStyle={receipt.status === "0x1" ? 'success' : 'danger'}>{receipt.status === "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash}</Alert>
</Fragment>
}

View File

@ -8,7 +8,7 @@ contract {{contractName}} {
{{/each}}
}
{{structName}}[] public items;
{{structName}}[] items;
event ItemCreated(uint id, address createdBy);
event ItemDeleted(uint id, address deletedBy);
@ -42,4 +42,9 @@ contract {{contractName}} {
emit ItemDeleted(_id, msg.sender);
}
function get(uint _id) public view returns ({{#each fields}}{{type}}{{#unless @last}},{{/unless}}{{/each}}) {
require(_id < items.length, "Invalid ArrayContractStruct id");
return ({{#each fields}}items[_id].{{name}}{{#unless @last}},{{/unless}}{{/each}});
}
}