Meteor 如何告诉流星;手表;数组中的更改?
我有这样的想法:Meteor 如何告诉流星;手表;数组中的更改?,meteor,Meteor,我有这样的想法: <template name ="products"> <br /> <h2>Products</h2> <table> <tr> <td>Name</td> <td>Price</td> </tr> {{#each produc
<template name ="products">
<br />
<h2>Products</h2>
<table>
<tr>
<td>Name</td>
<td>Price</td>
</tr>
{{#each products.items}}
<tr>
<td>{{name}}</td>
<td>{{price}}</td>
</tr>
{{/each}}
<tr>
<td>Total:</td><td>{{products.totalPrice}}</td>
</tr>
</table>
</template>
Template.products.helpers({
products: function () {
try {
var user = Session.get("user");
return JSON.parse(localStorage[user]); //this return*
} catch (e) {
}
}
});
产品
名称
价格
{{{#每个产品.项目}
{{name}}
{{price}}
{{/每个}}
总计:{{products.totalPrice}
模板.products.helpers({
产品:功能(){
试一试{
var user=Session.get(“用户”);
return JSON.parse(localStorage[user]);//此返回*
}捕获(e){
}
}
});
*这将返回如下内容:{totalPrice:30,items:[{“productId1”、“name1”、“10”}、{“productId2”、“name2”、“20”}
问题是:我需要将这些信息存储在localStorage中,而不是Meteor.Collection中,因为我不想在X时刻之前访问服务器(其实并不重要)。但我不能让这个东西在我更改本地存储值时自动更新。有没有办法做到这一点
提前感谢。将信息存储在
会话中,因为它是被动的,所以每次会话中的值更改时,模板都会更改
您还可以使用似乎使localstorage具有反应性的软件包。这就是它的用途。最简单的例子:
var array = [];
var arrayDep = new Deps.Dependency();
Template.name.helper = function() {
arrayDep.depend();
return array;
};
var change = function() {
// do things to Array contents
arrayDep.changed();
};
您不使用Meteor.Collection(null)
创建本地集合的任何原因?Meteor在哪里存储该本地集合?多谢了,其实是多谢的翻版,我会在几个小时后试试这个!谢谢,我会查出来的。