6b2f7cba85b3b7129e74b5db7b1a23df 中文文档教程
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 asmap
parameter orfalse
if an error occursfalse
if a property is not defined in thescope
object and themap
string requires it or if themap
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 asmap
parameter orfalse
if an error occursfalse
if a property is not defined in thescope
object and themap
string requires it or if themap
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