我正在尝试在淘汰赛3.2.0中使用新的组件系统.
目前没有太多文档,但这确实有效.
ko.components.register('price-input', {
template: '<span>price-input</span>'
})
Run Code Online (Sandbox Code Playgroud)
但是,template绑定允许您指定DOM中已存在的模板名称,例如:
<script type="text/html" id="price_input">
<span>price-input</span>
</script>
Run Code Online (Sandbox Code Playgroud)
然后你可以这样做:
<div data-bind="template: {name: 'price_input'}"></div>
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这个:
ko.components.register('price-input', {
template: {name: 'price_input'}
})
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有没有办法在新组件中使用命名模板,或者它们必须内联或加载AMD.
谢谢
编辑:在RP Niemeyer的回答之后,为了澄清这里的模板,我尝试了他的回答:
<script type="text/html" id="ifx_price_input">
<h4>PRICE INPUT <span data-bind="text: value"></span></h4>
</script>
Run Code Online (Sandbox Code Playgroud)
这是组件代码:
ko.components.register('price-input', {
template: {element: 'ifx_price_input'}
})
Run Code Online (Sandbox Code Playgroud)
它确实加载模板,但将其视为转义字符串.
想法?
最新的水线现在支持协会.这是一对多的例子
// A user may have many pets
var User = Waterline.Collection.extend({
identity: 'user',
connection: 'local-postgresql',
attributes: {
firstName: 'string',
lastName: 'string',
// Add a reference to Pets
pets: {
collection: 'pet',
via: 'owner'
}
}
});
var Pet = Waterline.Collection.extend({
identity: 'pet',
connection: 'local-postgresql',
attributes: {
breed: 'string',
type: 'string',
name: 'string',
// Add a reference to User
owner: {
model: 'user'
}
}
});
Run Code Online (Sandbox Code Playgroud)
这会owner在宠物集合上创建一个字段.除了使用现有数据库之外,这没什么问题.它称之为外键owner_id.
无论如何都要覆盖数据库中使用的字段名称?
在afterCreate和afterUpdate回调都返回模型.afterDestroy除了回调之外什么都不给你,beforeDestroy只给出了标准.
我很好奇,如果我做错了......
如果我使用afterDestroy我基本上被告知'记录'......'某处'....被摧毁.
如果我使用beforeDestroy我,那么我必须再次查看模型.
我知道sails不是'rails',但是对我来说生命周期回调可以访问模型,或者如果不是模型,至少它的值.....
你说什么风帆社区?