Vue.js vuejs嵌套json呈现
我必须使用json,它看起来是这样的:Vue.js vuejs嵌套json呈现,vue.js,vuejs2,Vue.js,Vuejs2,我必须使用json,它看起来是这样的: book_json={ "id": 2, "book": "Rockford mountain", "related_json": { "choice0": " The Good Friday Book", "choice1": "DRiven by Inspiration", "choice2": "Do good, be good", "choice3": "Autobiography Obama", "choice4": "None", "sele
book_json={ "id": 2, "book": "Rockford mountain", "related_json": { "choice0": " The Good Friday Book", "choice1": "DRiven by Inspiration", "choice2": "Do good, be good", "choice3": "Autobiography Obama", "choice4": "None", "select0": "choice0", "select1": "None" } }
在我的模板中,渲染时:
{{book_json.book} or {{book_json.id}} # all good
然而,我想展示的是:
{{book_json.related_json.{{book_json.related_json.select0}} }}
// result: `The Good Friday Book`
i、 e我想选择choice0
,它源于{{book\u json.related\u json.select0}
我花了几个小时在谷歌上搜索,但找不到一个方法来实现这一点
如果您有任何解决此问题的建议,我们将不胜感激。请尝试:
[[ book_json.related_json[book_json.related_json.select0] ]]
嗯,您试图以
choose0
的方式获取它,而在json中它是choice0
。@Mindastic:不,不是这样的。我现在通过更改json键来澄清它(我现在称它为select0
),而且,你不应该做{{book\u json.related\u json.{{{book\u json.related\u json.select0}}
,而是做{book\u json.related\u json.select0]}
。@Mindastic:hm{{book_json.related_json[book_json.related_json.select0]}
尝试起来似乎很有趣-但是我有一个小问题-我的后端是Django,所以我将自定义VueJs分隔符设置为[[
]]
如何处理您提到的内方括号[[book\u json.related\u json[book\u json.related\u json.select0]]]
-我试过了,但没用:(如果book\u json
是一个javascript变量,你想和Vue一起使用,那么你应该在方括号内调用它,而不是大括号内调用它。[[book\u json.related\u json[book\u json.related\u json.select0]]
。