get() 中返回的 Ractive 计算属性
Ractive computed attributes returned in get()
ref this jsfiddle
html:
<main />
<div id='result' />
代码:
window.ractive = new Ractive({
el: 'main',
template: '<p>a thing called {{thing}}</p>',
computed: { thing : function(){return "kablooie"} }
});
$('#result').html(JSON.stringify(ractive.get()))
这里的 ractive.get() 做 return 属性的值 "thing"。尽管文档说计算属性不是 return 由 get() 编辑的。
这是故意行为还是错误?
在您使用的 edge Ractive(将是 0.8)中,我们通过 ractive.get()
将计算和映射的属性添加到根 get 作为功能请求。
请参阅 this issue 了解当前提案,以便能够通过 ractive.get('.')
仅获取根数据对象,这意味着:
window.ractive = new Ractive({
el: 'main',
data: { foo: 'foo' },
template: '<p>a thing called {{thing}}</p>',
computed: { thing : function(){return "kablooie"} }
});
console.log( JSON.stringify( ractive.get() ) );
// { foo: 'foo', thing: 'kablooie' }
console.log( JSON.stringify( ractive.get('.') ) );
// { foo: 'foo' }
ref this jsfiddle
html:
<main />
<div id='result' />
代码:
window.ractive = new Ractive({
el: 'main',
template: '<p>a thing called {{thing}}</p>',
computed: { thing : function(){return "kablooie"} }
});
$('#result').html(JSON.stringify(ractive.get()))
这里的 ractive.get() 做 return 属性的值 "thing"。尽管文档说计算属性不是 return 由 get() 编辑的。
这是故意行为还是错误?
在您使用的 edge Ractive(将是 0.8)中,我们通过 ractive.get()
将计算和映射的属性添加到根 get 作为功能请求。
请参阅 this issue 了解当前提案,以便能够通过 ractive.get('.')
仅获取根数据对象,这意味着:
window.ractive = new Ractive({
el: 'main',
data: { foo: 'foo' },
template: '<p>a thing called {{thing}}</p>',
computed: { thing : function(){return "kablooie"} }
});
console.log( JSON.stringify( ractive.get() ) );
// { foo: 'foo', thing: 'kablooie' }
console.log( JSON.stringify( ractive.get('.') ) );
// { foo: 'foo' }