@wxmini/wxml-generator

1.0.1 • Public • Published

@wxmini/wxml-generator

将@wxmini/wxml-parser 生成的ast树转换回 wxml

用法

const { transformFromAST } = require('@wxmini/wxml-generator');

var ast = `{
    "tag": "body",
    "attr": {},
    "children": [{
        "tag": "view",
        "attr": {
            "class": "cate-container"
        },
        "unary": false,
        "children": [{
            "tag": "view",
            "attr": {
                "class": "cate",
                "wx:for": "{{cate}}",
                "wx:key": "index",
                "wx:for-item": "cateItem"
            },
            "unary": false,
            "children": [{
                "tag": "view",
                "attr": {
                    "class": "cate-label"
                },
                "unary": false,
                "children": ["{{cateItem.label}}"]
            }, {
                "tag": "view",
                "attr": {
                    "class": "cate-sub"
                },
                "unary": false,
                "children": [{
                    "tag": "view",
                    "attr": {
                        "bindtap": "jumpTo",
                        "class": "subcate",
                        "wx:for": "{{cateItem.subCate}}",
                        "wx:key": "id",
                        "wx:for-item": "subCateItem"
                    },
                    "unary": false,
                    "children": [{
                        "tag": "view",
                        "attr": {},
                        "unary": false,
                        "children": ["{{subCateItem.label}}"]
                    }, {
                        "tag": "textarea",
                        "attr": {},
                        "unary": true,
                        "children": []
                    }]
                }]
            }]
        }]
    }]
}`;

// 返回结果为wxml
const result = transformFromAST(ast);

Readme

Keywords

none

Package Sidebar

Install

npm i @wxmini/wxml-generator

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

9.13 kB

Total Files

10

Last publish

Collaborators

  • goumang2010