2014-11-06 31 views
-1

好的,讓我重申一下這個問題。我在新的流星,我不知道如何添加 我創建了一個流星集合稱爲在同一個集合中添加兩個項目

Products1 = new Meteor.Collection ('products1'); 

和收集我有幾個變量,其中包括:「瓦」和「wattsbal」。

這是應用http://orozcotest.meteor.com/products1的樣品(在這個網頁我不得不手動列「瓦totales」存儲通過存儲{{wats_tot}}的信息,這是暫時,而我學習如何添加),你可以在看到更新的副本https://github.com/orozcorp/myapp.git現在我想添加分別由變量「watts」和「wattsbal」標識的列「watts」和「watts balastro」。我也有下面的模板

Template.product1Form.events({ 
    'click .save':function(evt,tmpl){ 
     var codigo = tmpl.find('.codigo').value; 
     var tipo = tmpl.find('.tipo').value; 
     var watts = tmpl.find('.watts').value; 
     var wattsbal = tmpl.find('.wattsbal').value; 
     var watts_tot = tmpl.find('.watts_tot').value; 
     var precio = tmpl.find('.precio').value; 
     var precio_bal = tmpl.find('.precio_bal').value; 
     var numbal = tmpl.find('.numbal').value; 
     var mo = tmpl.find('.mo').value; 
     var horasvid = tmpl.find('.horasvid').value; 
     var lux_watt = tmpl.find('.lux_watt').value; 
     if(Session.get('editing_product1')){ 
      updateProduct1(codigo,watts, tipo, watts_tot, precio, precio_bal, numbal, mo, horasvid, wattsbal, lux_watt); 
     } else{ 
      addProduct1(codigo,watts, tipo, watts_tot, precio, precio_bal, numbal, mo, horasvid, wattsbal, lux_watt); 
     } 
     Session.set('showProduct1Dialog',false); 
     Session.set('editing_product1',null); 
    }, 
    'click .cancel':function(evt,tmpl){ 
     Session.set('showProduct1Dialog',false); 
     Session.set('editing_product1',null); 
    }, 
    'click .remove':function(evt,tmpl){ 
     removeProduct1(); 
     Session.set('showProduct1Dialog',false); 
     Session.set('editing_product1',null); 
    } 
}) 

現在在我的javascript文件我已經嘗試了所有下面的方法,我不斷收到未定義或NaN

Template.product1Row.helpers ({ 
    wattstotales1 : function(){ 
     var watts = tmpl.find('.watts').value; 
     var wattsbal=tmpl.find('.wattsbal').value; 
     var wattstotales = Number(watts) + Number (wattsbal); 
     return wattstotales; 
    } 

}); 

Template.product1Row.helpers ({ 
    wattstotales2 : function(){ 
     return Session.get('.watts').value + Session.get('.wattsbal').value; 
    } 

}); 

Template.product1Row.helpers ({ 
    wattstotales3 : function(){ 
     var watts = find('.watts').value; 
     var wattsbal = find('.wattsbal').value;  
     return watts+ wattsbal; 
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales4 : function(){ 
     var watts = Session.get(Number('.watts')).value; 
     var wattsbal = Session.get(Number('.wattsbal')).value; 

     return watts+ wattsbal; 
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales5 : function(){ 
     var watts = Number('watts'); 
     var wattsbal = Number('wattsbal');   
     return watts+ wattsbal; 
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales6 : function(){ 
     var watts = Number(Session.get('.watts').value); 
     var wattsbal = Number(Session.get('.wattsbal').value);  
     return watts+ wattsbal; 
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales7 : function(){ 
     var watts = Number(Session.get('watts').value); 
     var wattsbal = Number(Session.get('wattsbal').value);  
     return watts+ wattsbal; 
    } 
}); 


Template.product1Row.helpers ({ 
    wattstotales8: function() { 
     var a = $('products1.watts').val(); 
     var b = $('products1.wattsbal').val(); 
     var total = a+b; 
       return total;  
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales9: function() { 
     var a = Session.get('products1.watts').val(); 
     var b = Session.get('products1.wattsbal').val(); 
     var total = a+b; 
       return total;  
    } 
}); 

Template.product1Row.helpers ({ 
    wattstotales10: function() { 
     var a = Session.get(Number('products1.watts')).val(); 
     var b = Session.get(Number('products1.wattsbal')).val(); 
     var total = a+b; 
       return total;  
    } 
}); 

Template.products1.helpers ({ 
    wattstotales11 : function(){ 
     var watts = tmpl.find('.watts').value; 
     var wattsbal=tmpl.find('.wattsbal').value; 
     var wattstotales = Number(watts) + Number (wattsbal); 
     return wattstotales; 
    } 

}); 

Template.products1.helpers ({ 
    wattstotales12 : function(){ 
     return Session.get('.watts').value + Session.get('.wattsbal').value; 
    } 

}); 

Template.products1.helpers ({ 
    wattstotales13 : function(){ 
     var watts = find('.watts').value; 
     var wattsbal = find('.wattsbal').value;  
     return watts+ wattsbal; 
    } 
}); 

Template.products1.helpers ({ 
    wattstotales14 : function(){ 
     var watts = Session.get(Number('.watts')).value; 
     var wattsbal = Session.get(Number('.wattsbal')).value; 

     return watts+ wattsbal; 
    } 
}); 

Template.products1.helpers ({ 
    wattstotales15 : function(){ 
     var watts = Number('watts'); 
     var wattsbal = Number('wattsbal');   
     return watts+ wattsbal; 
    } 
}); 

Template.products1.helpers ({ 
    wattstotales16 : function(){ 
     var watts = Number(Session.get('.watts').value); 
     var wattsbal = Number(Session.get('.wattsbal').value);  
     return watts+ wattsbal; 
    } 
}); 

Template.products1.helpers ({ 
    wattstotales17 : function(){ 
     var watts = Number(Session.get('watts').value); 
     var wattsbal = Number(Session.get('wattsbal').value);  
     return watts+ wattsbal; 
    } 
}); 


Template.products1.helpers ({ 
    wattstotales18: function() { 
     var a = $('products1.watts').val(); 
     var b = $('products1.wattsbal').val(); 
     var total = a+b; 
       return total;  
    } 
}); 

Template.products1.helpers ({ 
    wattstotales19: function() { 
     var a = Session.get('products1.watts').val(); 
     var b = Session.get('products1.wattsbal').val(); 
     var total = a+b; 
       return total;  
    } 
}); 

Template.products1.helpers ({ 
    wattstotales20: function() { 
     var a = Session.get(Number('products1.watts')).val(); 
     var b = Session.get(Number('products1.wattsbal')).val(); 
     var total = a+b; 
       return total;  
    } 
}); 
+0

你的幫助函數不返回任何東西。該助手拼寫'watts_total'而不是'wattstotal',並且您顯示的代碼甚至不涉及您提到的集合。請嘗試更精確地詢問你的要求。 – 2014-11-06 22:38:32

回答

0

我終於找到了答案,

Template.product1Row.helpers ({ 
    wattstotales : function(){ 
     var total = Number(this.watts) + Number(this.wattsbal); 
     return total; 
     } 
    }) 
相關問題