我是 Backbone js 新手。有人可以帮我从我的 Angular 发送模板中的数据吗?
我的 View 有以下代码:
$('#top-bar').html(_.template($("#loginned-top-bar-template").html()));
我的模板包含
<li class="menu-item"><a href="javascript:void(0)" id="topbar-username"><%user_name%></a></li>
我想向它发送“awsome_user”。
如果有人能帮助我,那就太好了。
最佳答案
var compiled = _.template($("#loginned-top-bar-template").html());
var templateVars = {user_name : 'awesome_user' };
$('#top-bar').html( compiled(templateVars) );
<%user_name%>
应该是<%=user_name%>
如果你想打印变量。
如果您想使用其他user_name
,设置user_name
调用编译函数之前的属性。
var compiled = _.template($("#loginned-top-bar-template").html());
var templateVars = {user_name : 'awesome_user' };
templateVars.user_name = Parse.User.current().get("name");
$('#top-bar').html( compiled(templateVars) );
关于javascript - Backbone js。如何在backbone js中将数据从 View 传递到模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24477411/