mithril.js

simple bar plot with mithril.js and d3.js

折月煮酒 提交于 2021-01-29 08:47:07
问题 I am very very new to javascript and mithril.js. I am trying to create a very simple bar plot using mithril.js and d3.js. But, I am not having any luck even getting the axis in place. Firstly, I created a mithril "svg" component and appended a mithril "g" compent as follows: var g = m(gView, {transpose:"translate(10, 10)"}) var svg = m(SVGView, {width: 100, height:100}, g) where gView and SVGView are as follows: var gView = { view: function(vnode) { return m("g", vnode.attrs, [vnode.children]

How to detect model parameter change event in mithril.js?

ぃ、小莉子 提交于 2020-01-21 14:39:12
问题 I recently started learning mithril.js and I'm wondering how can I make very basic Model -> View one way data binding app. TestModel = function(data){ this.name = m.prop(data.name) } testModel = new TestModel({name: "John"}) code above declare a model and it works perfectly as getter/setter. but how can I set an event listener for the model event like Backbone's listenTo('model',"change",callbackFunc) ? all sample codes I saw are setting events for actual user actions like click , keyup or

How to convert a string into a HTML element in Mithril?

笑着哭i 提交于 2020-01-21 12:06:27
问题 Suppose I have a string <span class="msg">Text goes here</span> .I need to use this string as a HTML element in my webpage. Any ideas on how to do it? 回答1: Mithril provides the m.trust method for this. At the place in your view where you want the HTML output, write m.trust( '<span class="msg">Text goes here</span>' ) and you should be sorted. 回答2: Mithril it's powerfull thanks to the virtual dom, in the view you if you want to create a html element you use: m("htmlattribute.classeCss" ,

How to convert a string into a HTML element in Mithril?

 ̄綄美尐妖づ 提交于 2020-01-21 12:06:13
问题 Suppose I have a string <span class="msg">Text goes here</span> .I need to use this string as a HTML element in my webpage. Any ideas on how to do it? 回答1: Mithril provides the m.trust method for this. At the place in your view where you want the HTML output, write m.trust( '<span class="msg">Text goes here</span>' ) and you should be sorted. 回答2: Mithril it's powerfull thanks to the virtual dom, in the view you if you want to create a html element you use: m("htmlattribute.classeCss" ,

mithril.js redirect user if not connected

狂风中的少年 提交于 2020-01-06 02:18:08
问题 How to use mithril.js and it's routing system to redirect my user to the login form when the user is not yet connected? I define some routes: m.route.mode = 'search'; m.route(document.getElementById('app'), "/", { '/': LoginForm, '/orders': OrderList, '/order/new': OrderForm, '/order/:orderId': OrderForm }); But I want to redirect /orders and other routes to / if the user has not login. Do I need to put the code in the controllers (OrderList.controller and OrderForm.controller)? or in the

How do I show a spinner while waiting for an AJAX request in Mithril JS?

无人久伴 提交于 2019-12-20 18:43:13
问题 I'm using Mithril JS in a project and I'm having trouble understanding exactly how to go about hooking into the Ajax lifecycle. Like if I have an Ajax request takes awhile, I want to show a spinner. Pretty basic, but I can't seem to figure out how that can happen. I want to use the same container for the spinner as the content that the Ajax request is looking for. Here's my setup: var Thing = function (data) { var p = m.prop; this.title = p(data.title); this.timestamp = p(moment.unix(data

How does Mithril and jQuery interact with each other?

老子叫甜甜 提交于 2019-12-20 11:37:17
问题 I am using Mithril as our MVC framework & I want to leverage of rich JQuery/Jquery UI functionalities. I would like to understand the 'Do's and Don't's' when combining jQuery with Mithril What I understand is, I can use Mithril config to access the real DOM element & bind to various jQuery functions safely. Using jQuery UI functions with Mithril But what about using jQuery selectors on classes or ids to locate the real DOM element, like attaching a jQuery date picker beforeShow: function

How does Mithril and jQuery interact with each other?

五迷三道 提交于 2019-12-20 11:37:06
问题 I am using Mithril as our MVC framework & I want to leverage of rich JQuery/Jquery UI functionalities. I would like to understand the 'Do's and Don't's' when combining jQuery with Mithril What I understand is, I can use Mithril config to access the real DOM element & bind to various jQuery functions safely. Using jQuery UI functions with Mithril But what about using jQuery selectors on classes or ids to locate the real DOM element, like attaching a jQuery date picker beforeShow: function

Using jQuery UI functions with Mithril

纵饮孤独 提交于 2019-12-12 16:26:51
问题 I am new to the Mithril JS framework and I love its rendering performance. It being light-weight is a plus, but I would like to use jQuery UI so that I can benefit from some of its functionality such as the draggable interaction. From my understanding, both jQuery UI and Mithril manipulate DOM elements. If so, how practical is it to use jQuery UI with Mithril? 回答1: Your question is a bit open ended, but to give a useful answer: Mithril templates don't actually touch the DOM until you call

Mithril: cannot m.redraw with m.render

你说的曾经没有我的故事 提交于 2019-12-12 04:41:33
问题 I have an app where I want to control when to redraw the view. I can make it work using m.mount and m.redraw : var count = 0; var Counter = { view: function() { return m('main', [ m('h1', ('Count: ' + count)) ]) } } m.mount(document.body, Counter); window.setInterval(function () { count++; m.redraw(); }, 200); <html> <body> <script src="https://unpkg.com/mithril/mithril.js"></script> <script src="index.js"></script> </body> </html> But if i use m.render (because I don't need mithril to