问题标签 [ractivejs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
383 浏览

javascript - Ractive.js 将对象设置为无线电输入值

是否可以将对象设置为无线电输入的值?

它尝试了这个http://jsfiddle.net/benroe/fah5f/3/,但它不起作用。那是一个错误吗?

#模板

javascript

0 投票
1 回答
373 浏览

data-binding - 使用 RactiveJs 两种方式绑定输入

我刚开始使用 RactiveJs 并且在观察输入标签时遇到了一些麻烦,该标签最初是用一个值呈现的。

我正在观察下面的输入字段。

使用以下

挑战是第一次“date_modified”是未定义的更改“oldValue”。第二次“date_modified”更改“oldValue”正确返回旧值。

“date_modified”最初是用一个值(例如,22/11/2014)呈现的,我怀疑这可能是问题,因为当模板 I 时,所有示例都将输入留空

有什么想法吗?

谢谢

0 投票
2 回答
638 浏览

javascript - 如何在 RactiveJS 的装饰器中访问对象

我在 RactiveJS 中使用 Pikaday 日期选择器作为装饰器,并希望在装饰器之外访问日期选择器的 api,但将其添加到返回对象似乎不起作用。有人可以指出我正确的方向吗?

http://jsbin.com/lefiyume/1/edit?html,js

0 投票
2 回答
3444 浏览

javascript - Ractive.js 中的异步数据加载

我喜欢在渲染一个活跃的模板时提取一些远程数据。由于请求的异步性质,没有数据将其输出。我怎样才能做到这一点?

0 投票
1 回答
214 浏览

javascript - Restrict usage of scripts defined outside of RequireJS scope

I have a problem with scopes (global variables/namespaces) that i just can't fix. The thing is that I have some legacy code on a project in which i added new functionalities using Require.js. This legacy code is loaded using standard <script> tags, but the new code is loaded with Require. The problem occurs when I add the Ractive.js in Require as AMD. Because legacy code loads Prototype.js, it has some clashes with Ractive.js.

The main problem is when observing the array for changes. Specifically, when i observe the array with pattern observer.

ractive.observe('dataArray.*', function(newValue, oldValue, keypath) { alert(' status changed from ' + oldValue + ' to ' + newValue); }, {debug: true, init: false});

If i don't add observer to array, everything works, but if I add it, i get an error undefined is not a function in prototype.js (this doesn't happen when I remove prototype.js from globals).

Another this is that it actually works when i don't use the pattern observer.

So, my question is, is there a way to configure Require.js to use only the scripts that are loaded as AMD-s? Or, in other words, restrict the scope of AMD scripts to only each other so it ignores global scripts?

Thanks in advance.

0 投票
1 回答
251 浏览

javascript - 除非在 RactiveJS 中指定,否则为什么我的组件无法获取其父级数据

我创建了一个在父级中调用的组件,但是在尝试通过 keypath 函数获取组件中的值时,它是空的。现在,除非我直接在组件的模板中调用此键路径,否则即使它仍然存在于父级中,它似乎也不存在。下面的例子来说明这一点。

http://jsbin.com/golen/1/edit?html,js

0 投票
1 回答
2500 浏览

javascript - 在 Ractive.js 中使用 HTML 标签呈现内容

我试图在 Ractive.js 呈现的数据中包含 HTML 标记(自动下标化学符号,以防万一有人关心),但 Ractive 只是插入文本而不是创建新的 DOM 元素。

一个最小的测试用例,改编自60 秒设置指南

正如您在这个 JSfiddle中看到的那样,结果Hello, <b>world</b>不是预期的“Hello, world

我猜这与 Ractive 处理表达式的方式有关。但我还没有到源代码有意义的地步。

关于如何获得预期行为的任何想法?

0 投票
1 回答
238 浏览

javascript - RactiveJS:如何在模板表达式中测试相等性?

我正在使用 Ractive.JS 绑定:

模板使用模板表达式来检测一个项目是否是当前选定的项目并相应地添加一个类:

选择一个项目后,我运行:

设置后,我可以看到条件始终为假,即使条件应该为真。我还通过添加以下内容进行了检查:

在警报中确认该项目已被实际选中。

在此处输入图像描述

然而,条件仍然是错误的,并且没有设置类。

如何在模板表达式中测试相等性?

0 投票
1 回答
585 浏览

ractivejs - 如何更新部分

您好 RactiveJS 用户,我是新来的,我对使用 RactiveJS 感到非常兴奋,但是我想知道是否可以更新 Ractive 实例中的模板/数据。

我有以下模式窗口:

>content是一个排名模板。想象点击一个玩家需要用 playerProfile 模板和它请求的数据覆盖排名。除了拆解,还有另一种方法可以完成,然后使用 playerProfile 模板重新初始化模态窗口?

更新

我忘了提到这个窗口目前将包含 20 个模板(随着游戏变得越来越复杂,这些模板会在未来增长)。我所说的窗口是主模式窗口,它显示用户触发的每个模板,如排名、邮件、报告、部落、地图等。

问候。

解决方法 Marty 的回答是正确的,但我不想让自己复杂化,只是在#content div 中创建 Ractive 的新实例,而不是创建整个模态窗口的不同实例,这些实例将在初始化时显示并在拆卸时隐藏。

0 投票
1 回答
604 浏览

javascript - Observer doesn't detect array push

as I've been discovering this library more and more, I'm stuck at this one single thing.

I have this staticData array:

And this Ractive instance:

My buildingsQueue will get processed one at a time, and the townController will set the current key to true so I decided to make an observer for queue.* following Rich's example

The problem is that buildingQueue changes over time, and pushing data like the following doesn't fire the observer callback:

The observer doesn't fire as Rich's documentation says it should in it's example. My logic is that observers only work with the array items that are in the array when initiated, but I'm pretty sure that's not true and it should work with dynamic arrays, so, please enlighten me on this one.

TO BE AWARE OF I'm firing the push events from outside the init function , Javascript Console for example, or another javascript object.

FIXED PROLEM I've updated the plugin to the edge version, still 0.4.0 like the one I was using, but, this one was released two days ago. Thanks Rich and Marty, whatever you did in those commits.