问题标签 [mithril.js]

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 投票
1 回答
234 浏览

jquery - MithrilJS 在 m() 调用上将变量传递给配置

我正在尝试让 jQuery FooTable 插件在我的秘银应用程序中工作。我的组件中有这样的配置调用:

args.configRows 是我从传递给该组件的 GET 请求返回的承诺。我可以看到它确实成功地调用了我的 execFooTable 函数,但我似乎无法弄清楚如何访问我的 args.configRows 变量。我已经尝试过 context.configRows 和其他一些东西,但它们都以未定义的形式返回。

谁能帮帮我?谢谢你。

0 投票
1 回答
644 浏览

ajax - 如何使用 Mithril 将 AJAX 请求格式化为带有身份验证密钥的 API?

以下 GET 请求使用 jQuery 工作:

但随后使用 Mithril 进行的改编将不起作用:

在查阅https://lhorie.github.io/mithril/mithril.request.html上的文档并搜索类似示例后,我尝试了不同的变体。我正在考虑使用 3rd 方库,但我想我会在这里尝试,然后再深入兔子洞。当我尝试发出 AJAX 请求时收到的错误消息是我丢失了 API 密钥,即使它就在那里。

更新:

从那以后,我了解到,除了下面标记的答案之外,Mithril 会自动将 API 响应解析为 JSON。由于我从这个 API 得到一个字符串响应,我必须在我的m.request对象中包含以下条目:

反序列化告诉 Mithril 按原样返回响应值,而不是 JSON。

0 投票
1 回答
53 浏览

mithril.js - 赋值语法是否意味着任何代码?

赋值语法是否意味着任何代码?

虽然基本赋值语法和 ... 都可以达到相同的效果,但通常建议您尽可能使用赋值语法,因为它更易于阅读。

https://lhorie.github.io/mithril/mithril.request.html


我添加了

什么时候可以赋值语法?</p>

用户.json

索引.html


我添加了

「通常建议你尽可能使用赋值语法」是指下面的代码?</p>

用户.json

索引.html

或者

0 投票
1 回答
122 浏览

mithril.js - 在处理 Web 服务数据中,为什么不需要 m.prop?

请注意,在 AJAX 请求完成之前,此 getter-setter 保持未定义的值。


但是下面的代码没有使用m.prop。为什么?

您是否以不同的方式设置默认值?


如果在上面的代码中没问题,在下面没用?

https://lhorie.github.io/mithril/mithril.request.html

0 投票
1 回答
288 浏览

javascript - 为什么不使用 Mithril 中的 m.request 重绘视图?

我有这个例子:

第一次请求没问题,但是当我点击文件夹时,第二个请求没问题,但视图没有重绘,为什么?

0 投票
1 回答
84 浏览

ruby-on-rails - 添加 gem 'mithril_rails' 后出错

我在我的 Gemfile 中添加 gem 'mithril_rails' , make bundle installand bundle update,添加//= require mithril到我的application.js文件中,输入rails s并得到错误:

/Users/myusername/.rvm/gems/ruby-2.2.2/gems/mithril_rails-0.0.7/lib/mithril_rails/rails/engine.rb:5:in block in <class:Engine>': undefined methodregister_engine' 为 nil:NilClass (NoMethodError)

我使用 rails 4.2.3,mongoid。

我能做些什么?

0 投票
1 回答
73 浏览

mithril.js - 为什么通过将它作为参数传递给 .then 方法,我可以绑定预先存在的 getter-setter 吗?

您可以通过将预先存在的 getter-setter 作为参数传递给 .then 方法来绑定它:

好的

NG


为什么通过将它作为参数传递给 .then 方法,我可以绑定预先存在的 getter-setter 吗?

这个语法的规范是 Promise? 或者这个语法的规范是秘银?

※我可以理解 m.prop() 是 getter-setter。


在内部对 Promise 对象进行了什么样的处理?

而实现是库代码的哪一部分?

0 投票
1 回答
633 浏览

javascript - Mithril.js with multiple GET requests

My project was originally in Angular, you can see it on GitHub still. But I'm trying to switch to Mithril.

I'm calling the request on the data.json file (served from GitHub Pages), which is just a list of events ordered by date (ordered at the time of compilation). The load time for the entire file is getting a little questionable, and it's only going to get worse.

My initial solution is to try to load a smaller initial subset of the data (via another file) and then load the rest, but I'm not sure how to do that with Mithril. (Additionally I'll eventually need to do some computation on the data before it's output, if that has any relevance. Like adding attributes to mark year and month boundaries.)

The current relevant code is just this.eventlist = m.request({method: "GET", url: "data.json"}); sitting in the controller. Any suggestions on how I might do this in Mithril (or any suggestion for a better idea) would be appreciated.

Here is the code I have so far:

0 投票
3 回答
174 浏览

html - 使用秘银将 HTML 嵌套在字符串中

我想用 Mithril's 生成以下 HTML m

<p>I am a <code>person</code></p>.

我目前正在m.trust为此使用:

m.trust("<p>I am a <code>person</code></p>").

但我不喜欢 HTML 字符串。有一个更好的方法吗?

0 投票
1 回答
203 浏览

javascript - 追踪 mithril.js 自动重绘系统

我打算使用 mithril.js 编写一个性能敏感的应用程序,该应用程序将有数千个可以随时更新的 DOM 元素,我必须确保只有更新的元素才会被重绘。

我的问题是,有没有办法让秘银自动重绘系统记录 DOM 更改(到浏览器控制台或任何地方),以便我可以查看它并绝对确定只有预期的 DOM 元素被更改?我想防止我自己的逻辑错误,并确信秘银只是接触改变的元素。