我想创建自己的模板,我可以传递一个对象,并让Soy模板迭代对象并拉出键和值.
如果我在JavaScript中有对象并调用Soy模板:
var obj = {'one':'a', 'two':b, 'three':c};
nameSpace.templateName({'paramValue': obj});
Run Code Online (Sandbox Code Playgroud)
我如何获得['one', 'two', 'three']价值?通常我会使用jQuery的each()功能,但我不知道如何在没有将对象转换为数组的情况下在Soy文件中做类似的事情.
我正在使用的对象具有已知的形式(没有嵌套对象,或者如果有的话,它们是提前知道并且已知的深度).欢迎使用嵌套对象的此答案或一般对象案例的答案.
{namespace nameSpace}
/**
* Prints keys and values of the object
* @param paramValue object with keys and values
*/
{template .templateName}
{$paramValue[0]} // undefined
{$paramValue.Keys} // undefined
{$paramValue.keys} // undefined
{$paramValue.one} // prints 'a'
{foreach $val in $paramValue}
// never reached
{/foreach}
{/template}
Run Code Online (Sandbox Code Playgroud) 我有一个对话框,显示动态大小的表单.我目前使用以下代码自动调整对话框的大小.我希望它做的是在调整大小事件发生后自动重定位对话框.这是因为对话框调整了宽度,我希望它在页面后缀中保持居中.
$("#form-div").dialog({
autoOpen: false,
width: "auto",
height: "auto",
resize: "auto",
modal: true
});
$("#show-form-button").click(function() {
$("#form-div").dialog("open");
});
Run Code Online (Sandbox Code Playgroud)
编辑:
只是为了清楚
该对话框显示一个表单.显示表单后,可能会向表单添加其他字段,使其不再适合原始对话框."resize:'auto'"选项会自动处理此问题并调整对话框的大小.我想让对话框在自动调整大小后居中.