2015-12-02 103 views
0

嘗試使用引導酥料餅與MeteorJS並有2個煩惱:酥料餅與MeteorJS

  1. 不能分配從收集來的輸入值
  2. 我試圖得到一個html,body但酥料餅有一定的價值每個模板每酥料餅,這是正常的,但我儘量1個屏幕上只能做1米酥料餅

我有收集Posts該等文件Posts.insert({title:"Loli Pop"});

Meteor.publish("posts_levels", function(){ 
    return Posts.find(); 
}); 

<template name="www"> 
{{#each level}} 
    {{> one}} 
{{/each}} 
</template> 

Template.www.onCreated(function(){ 
    var self = this; 
    self.autorun(function() { 
     self.subscribe('posts_levels'); 
    }); 
}); 

<template name="one"> 
    <div class="popover-markup"> 
     <div class=" trigger "> 
      Edit 
     </div> 
    </div> 
    <div class="content-popover hide"> 
     <form class="form"> 
      <input name="title" id="post_edit_title" value="{{title}}" /> 
     </form> 
    </div> 
</template> 

Template.one.onRendered(function(){ 
    $('.popover-markup > .trigger').popover({ 
    html : true, 
    content: function() { 
     return $('.content-popover').html(); 
    }, 
    container: 'body', 
    placement: 'right' 
}); 

編輯: 2問題就迎刃而解了50%,我添加此,現在它躲到Ë當我打開另一酥料餅的,但後來我必須點擊.trigger 2倍,顯示新酥料餅

$('.popover-markup > .trigger').popover({ 
    html : true, 
    content: function() { 
     return $('.content-popover').html(); 
    }, 
    container: 'body', 
    placement: 'right' 
    }).on("click", function(e){ 
     $('.trigger').not(this).popover('hide'); 
    }); 
+0

我會建議問2個問題。並告訴我們你已經發現哪些不起作用。它看起來並不是所有的代碼都是在你的問題中才能理解問題。你提到一個我們在你的問題中沒有看到的集合。 –

+0

@josharink我會編輯這個問題,1分鐘 – Qwe

+0

@josharink完成!如果你能幫忙,這將是非常棒的! – Qwe

回答

0

這裏是你的問題1(從收集值分配給輸入)的anwser。

模板中的輸入獲取標題的值。當您刪除hide類時,您可以看到集合中的標題。但是,彈出窗口將新元素插入到DOM中。這些新元素由Bootstrap渲染而不是由Blaze渲染,所以輸入不會被填入title的值。

您可以做的是在顯示彈出窗口時將事件處理程序附加到彈出窗口。類似這樣的:

Template.one.onRendered(function(){ 
$('.popover-markup > .trigger').popover({ 
     html: true, 
     content: function() { 
      return $('.content-popover').html(); 
     }, 
     container: 'body', 
     placement: 'auto top' 
    }).on('shown.bs.popover', function() { 
     $('.popover-content #post_edit_title').val(this.data.title); 
    }.bind(this)); 
}); 

正如你所看到的事件shown.bs.popover可以用來做一些初始化。在事件處理程序中設置輸入的值。 讓jquery選擇器在彈出窗體中查找輸入非常重要,這就是選擇器以.popover-content開頭的原因。否則,它會將值設置爲模板中定義的第一個輸入。

另外需要注意的是使用bind(this)。這附加this並使其在事件處理程序內部可用,以便您可以獲得標題的值。

順便說一句,popover結束時還有一個hidden.bs.popover事件。