6b2f7cba85b3b7129e74b5db7b1a23df 中文文档教程

发布于 8年前 浏览 25 更新于 3年前

DataBind

用于 javascript 对象(提供者)和字符串(消费者)之间数据绑定的模块,将同步数据保存到新对象中。

Installation

$ npm install 6b2f7cba85b3b7129e74b5db7b1a23df --save

function dataBind(map, scope)

Params
  • (string) map: The string template, a valid javascript object
  • (object) scope: The data object
Returns
  • Object with same format as map parameter or false if an error occurs
  • false if a property is not defined in the scope object and the map string requires it or if the map string has an incorrect syntax

示例:

var dataBind = require('6b2f7cba85b3b7129e74b5db7b1a23df')

var map = '{Data: {property1: data.prop}, Other: {propertyN: other.data} }'

var scope = {
    'data': {
        'prop': 'VALUE 1'
    },
    'other': {
        'data': 'VALUE 2'
    }
}

var result = dataBind(map, scope)

结果变量将包含

{
    "Data": {
        "property1": "VALUE 1"
    },
    "Other": {
        "propertyN": "VALUE 2"
    }
}

Other info

Publish 包,在代码更改时运行测试任务

$ gulp

单元测试和代码覆盖任务

$ gulp test

DataBind

Module used for data binding between a javascript object (provider) and a string (consumer), saves the synchronized data into a new object.

Installation

$ npm install 6b2f7cba85b3b7129e74b5db7b1a23df --save

function dataBind(map, scope)

Params
  • (string) map: The string template, a valid javascript object
  • (object) scope: The data object
Returns
  • Object with same format as map parameter or false if an error occurs
  • false if a property is not defined in the scope object and the map string requires it or if the map string has an incorrect syntax

Example:

var dataBind = require('6b2f7cba85b3b7129e74b5db7b1a23df')

var map = '{Data: {property1: data.prop}, Other: {propertyN: other.data} }'

var scope = {
    'data': {
        'prop': 'VALUE 1'
    },
    'other': {
        'data': 'VALUE 2'
    }
}

var result = dataBind(map, scope)

The result variable will contain

{
    "Data": {
        "property1": "VALUE 1"
    },
    "Other": {
        "propertyN": "VALUE 2"
    }
}

Other info

Publish package, runs test tasks when the code changes

$ gulp

Unit tests and code coverage tasks

$ gulp test
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文