如果我有一个Container带有子模板的父模板Contentavec只有一个按钮:
<head>
<title>test</title>
</head>
<body>
{{> Container}}
</body>
<template name="Container">
{{# Content callback = callBack }}
<button>ok</button>
{{/Content}}
</template>
<template name="Content">
{{> UI.contentBlock}}
</template>
Run Code Online (Sandbox Code Playgroud)
如果可以通过一个功能callback.像那样 :
Template.Container.helpers( {
callBack: function () {
return function () {
console.log( 'this is my callback' );
}
}
} );
Run Code Online (Sandbox Code Playgroud)
所以在我的内容模板中,我可以从父模板中调用一个函数.比如这样:
Template.Content.events( {
'click button': function ( e, tmpl ) {
tmpl.data.callback();
}
} );
Run Code Online (Sandbox Code Playgroud)
但有时候,我需要以另一种方式实现它.父母在他的孩子中调用一个函数.你这样做的方式是什么?
编辑:
我将它保存在一个meteorpad中以显示它的实际效果并使其易于分叉:http://meteorpad.com/pad/48NvCFExxW5roB34N/test-pass-callback-to-parent
假设我有一个非常简单的模板:
<script type="text/x-handlebars" data-template-name='myTemplate'>
<h1>{{name}}</h1>
<div>{{content}}</div>
</script>
Run Code Online (Sandbox Code Playgroud)
一个看起来像这样的模型:
model = {
name: 'My name',
content: 'some content <a href="target">with a link</a> and some <i>italic</i> text'
}
Run Code Online (Sandbox Code Playgroud)
我没有制作模型,我从Web服务加载它,它将有(或没有)html标签.
"我的名字"已正确呈现,但内容呈现为字符串而不是解释为html.
如何强制ember在模板中呈现html
我有像这样的d3.js生成的svg:
<svg height="1094" width="1254">
<g id="countries" stroke-width="1px" transform="">
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id1" class="1"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id2" class="1"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id3" class="3"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id4" class="1"></path>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我想做那样的somtehing:
foreach(path in #countries){
if(this.class === 3){dostuff}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过jquery方式:
$('#countries').find('path').each(function( index ) {
console.log(this);
});
Run Code Online (Sandbox Code Playgroud)
......什么都不记录
我尝试过d3.js方式(各国初始化如下:)countries = svg.append('svg:g').attr('id', 'countries'):
countries.select('path').each(console.log(this));
countries.selectAll('path').each(console.log(this));
Run Code Online (Sandbox Code Playgroud)
记录窗口对象(wtf?)
我有一个简单的出版物:
return Companies.find({}, {fields: {'myField1': 1, 'myField2': 1}});
在我的Companies收藏中,对于每个公司,我都有一个数组customers和一个数组managers.这些数组包含具有'_id'和各种其他属性的对象.
对于可视化,可以添加新公司,如下所示:
Companies.insert({
customers: [{_id: <userId>, otherProp: <data>}, ...],
managers: [{_id: <userId>, otherProp: <data>}, ...]
});
Run Code Online (Sandbox Code Playgroud)
该_id字段是users集合中相应用户的id.
我想只返回那些可以在customers数组的对象(或管理器数组,具体取决于用户)中找到用户的_id的公司.
这可能是一个mongo问题,但我不确定.=>在文档中,他们提到了mongo选择器:http://docs.meteor.com/#selectors ( http://docs.mongodb.org/manual/reference/operator/query/)但我无法弄清楚如何把它用于我的情况.
我正在使用mongodb,node.js和socket.io,我正在尝试减少访问数据库的数量.我需要更新一行; 然后返回更新的行,这就是我的方法:
db.collection('users').update({_id:targetID}, {$set: { 'property': 'value' }}, {safe:true}, function(err, result) {
db.collection('users').find({_id:targetID}).toArray(function(error, results){
//a socket.io resend the content
});
});
Run Code Online (Sandbox Code Playgroud)
它有效,但我真的感觉像是在这里做了一个无用的步骤.更新函数的回调似乎是一个布尔值.
顺便说一下,有没有比这个更好的文档:http://docs.mongodb.org/manual/applications/update/?我想找一个属性和方法列表.在{safe:true}为实例.没有它似乎没有用,但我在参考文献中找不到它.
也许我完全错了,这不是我应该这样做的方式.如果你有更好的主意...... :)
javascript ×3
meteor ×2
mongodb ×2
collections ×1
d3.js ×1
ember.js ×1
html5 ×1
jquery ×1
meteor-blaze ×1
node.js ×1
socket.io ×1
svg ×1