Bret Victor 几年前为响应式文档创建了一个名为 Tangle 的很酷的库。你可以在这里看到一个例子: http://worrydream.com/Tangle/TangleTemplate.html
我喜欢您可以拖动值的简单方式。我正在尝试构建一个简单的抵押贷款计算器,您可以在其中拖动利率、年限等。我希望在我的 UI 中做类似的事情并让 Meteor 处理 react 性。
我最初的想法是利用 TangleKit ( http://worrydream.com/Tangle/TangleKit/ ) 的 UI 元素,也许是通过从 JS 文件创建一个包?我不知道最好的方法或是否有其他方法。因此,寻求建议或想法以使用 Meteor 获得最终结果。
完整文档在这里: http://worrydream.com/Tangle/download.html
Git 存储库在这里: https://github.com/worrydream/Tangle
感谢您的指导。这对我来说是全新的。
------- 太平洋标准时间 4 月 14 日晚上 9 点更新
仍然没有运气,但我认为接近。见下文。
咖啡:
if Meteor.isClient
console.log "Client is alive."
Session.set("cookies", 4)
Template.reactive.cookies = () ->
Session.get("cookies")
Template.reactive.calories = () ->
Session.get("cookies") * 50
Template.reactive.events
'click .EditableValue': () ->
newCookies = Math.round(accounting.formatNumber((Random.fraction() * 10),1))
Session.set("cookies", newCookies)
Template.example.rendered = () ->
element = @find("#example") # Searches only within this template
tangle = new Tangle(element,
initialize: ->
@cookies = 4
@caloriesPerCookie = 50
update: ->
@calories = @cookies * @caloriesPerCookie
# Insert your Meteor updating code here, for example:
Session.set("cookiesQuantity", @cookies)
)
Template.example.cookies2 = () ->
Session.get("cookiesQuantity")
if Meteor.isServer
console.log "Server is alive."
HTML:
<head>
<title>Reactive Document</title>
</head>
<body>
{{> reactive}}
{{> example}}
</body>
<template name="reactive">
<h5>This is a simple reactive document.</h5>
<h4 id="example">When you eat <span class="EditableValue"> {{cookies}} cookies</span>, you will consume <span class="ReactiveValue"> {{calories}} calories</span>.</h4>
</template>
<template name="example">
<p>This is a simple reactive document.</p>
<p id="example">When you eat <span data-var="cookies"
class="TKAdjustableNumber" data-min="2" data-max="100"> cookies</span>, you
will consume <span data-var="calories"></span> calories.</p>
{{cookies2}}
</template>
最佳答案
看起来您可以按原样使用 Tangle,并在 tangle 的 update
函数中添加一两行代码以告知 Meteor 有关更改。
以您链接的示例为例,将页面转换为 Meteor 模板:
<template name="example">
<p>This is a simple reactive document.</p>
<p id="example">When you eat <span data-var="cookies"
class="TKAdjustableNumber" data-min="2" data-max="100"> cookies</span>, you
will consume <span data-var="calories"></span> calories.</p>
</template>
然后在该模板的 rendered
回调中初始化 Tangle:
Template.example.rendered = function () {
var element = this.find("#example"); // Searches only within this template
var tangle = new Tangle(element, {
initialize: function () {
this.cookies = 4; // Or Session.get("cookiesQuantity"), for example
this.caloriesPerCookie = 50;
},
update: function () {
this.calories = this.cookies * this.caloriesPerCookie;
// Insert your Meteor updating code here, for example:
Session.set("cookiesQuantity", this.cookies);
}
});
并确保将 Tangle 的文件放在 client/lib/tangle
文件夹中,以便将它们发送到客户端。
关于meteor - 具有 Meteor 处理 react 性的可拖动 UI 值(参见 Bret Victor 的 Tangle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23037694/