Mithril.js: it's bad for special character,when you use ‘map’ or redraw.

Created on 18 Aug 2020  Â·  2Comments  Â·  Source: MithrilJS/mithril.js

code1

var test=[
    "testVal<br>by used",
    "testVal&#10;by used2"
]

m.render(document.body,test.map(function(item){
    return m("p",item)
}))

mithril do not handle "br" or "#10;"

code2

//use m.request() to back this json
var test={
    val1:"testVal<br>by used",
    val2:"testVal&#10;by used2"
}

var show={
    oninit:function(){
        m.requery().then()
        //response test's json
    },
    view:function(){
        //return m("div",test.val1.replace("<br>","\n"))   
        return m("div",test.val2.toString()) 
    }
}

Throw errors!
like 'replace' or 'toString',all JS string-methods not be used in this example;

Question

Most helpful comment

@cnSonkwl

  • first code: Mithril does not normally process html, for that you need to use m.trust, like this
  • second code: you have a typo: m.requery should be m.request, but other than that it should work

Edit: the numeric html code for line feed will still not work

All 2 comments

@cnSonkwl

  • first code: Mithril does not normally process html, for that you need to use m.trust, like this
  • second code: you have a typo: m.requery should be m.request, but other than that it should work

Edit: the numeric html code for line feed will still not work

Oh yes , m.trust works well for code1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hadihammurabi picture hadihammurabi  Â·  4Comments

omenking picture omenking  Â·  3Comments

tivac picture tivac  Â·  3Comments

barneycarroll picture barneycarroll  Â·  3Comments

josephys picture josephys  Â·  4Comments