我正在尝试在下面的脚本中传递一个数组,但它并没有被识别为一个数组。以下是传递给jquery-template的哈希结构。options 是我想要传递的数组。
{
"options": [
[
"category 1",
"category 1",
[
[
"subcategory 1",
"subcategory 1",
[
[
"item 1",
"item 1"
],
[
"item 2",
"item 2"
]
]
],
[
"subcategory 2",
"subcategory 2",
[
[
"item 1",
"item 1"
],
[
"item 2",
"item 2"
]
]
]
]
]
]
}
我有这段jquery-template的代码需要渲染,当我将选项传递给下面的data_tree时,它不作为数组而是作为非字符串,导致出错。
<script id="nestedFieldTemplate" type="text/x-jquery-tmpl">
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#div_ff').nested_select_tag({
initValues: {
"subcategory_val":null,
"item_val":null,
"category_val":null
},
default_option: "<option value='-1'>...</option>",
data_tree: ${options},
});
});
{{html "</sc"+"ript>"}}
</script>
我尝试将其作为普通的JavaScript变量传递,但没有成功。我想在下面的代码中将jquery-template变量作为数组传递。
以下是它生成脚本的方式。
jQuery(document).ready(function(){
jQuery('#div_ff_ffs_02').nested_select_tag({
initValues: {
"subcategory_val":null,
"item_val":null,
"category_val":null
},
default_option: "<option _tmplitem="14" value='-1'>...</option>",
data_tree: category 1,category 1,subcategory 1,subcategory 1,item 1,item 1,item 2,item 2,subcategory 2,subcategory 2,item 1,item 1,item 2,item 2,subcategory 3,subcategory 3,,category 2,category 2,subcategory 1,subcategory 1,item 1,item 1,item 2,item 2,
});
});