Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import { Component, h, Prop, State } from "@stencil/core";
  2.  
  3. @Component({
  4. tag: "parent-component"
  5. })
  6. export class MyParent {
  7.  
  8. @Prop() carddata: any;
  9.  
  10. render() {
  11. return (
  12. <div>
  13. <child-component
  14. carddata={this.carddata}
  15. />
  16. </div>
  17. );
  18. }
  19. }
  20.  
  21. import { Component, Prop, h } from "@stencil/core";
  22.  
  23. @Component({
  24. tag: "child-component"
  25. })
  26. export class MyChild {
  27.  
  28. @Prop() carddata: any;
  29.  
  30. renderItems(items: string[]): string {
  31. let newString = "";
  32. items.map((item: string) => {
  33. newString = newString.concat(item, ", ");
  34. });
  35. return newString.substr(0, newString.length - 2);
  36. }
  37.  
  38. render() {
  39. const { items } = JSON.parse(this.carddata);
  40. return (
  41. <p>
  42. Items: <b>{this.renderItems(items)}</b>
  43. </p>
  44. );
  45. }
  46. }
  47.  
  48. [...]
  49.  
  50. import * as cardData from "./card-mock-data.json";
  51.  
  52. [...]
  53.  
  54. render() {
  55. return (
  56. <Wrap>
  57. <parent-component
  58. carddata={JSON.stringify(cardData)}/>
  59. </Wrap>
  60. );
  61. }
  62.  
  63. [...]
  64.  
  65. ChildComponent.prototype.renderItems= function (items) {
  66. var newString = "";
  67. items.map(function (item) {
  68. newString = newString.concat(item, ", ");
  69. });
  70. return newString.substr(0, newString.length - 2);
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement