Javascript Can';具有主干的t访问模型属性。木偶
我对使用item/composite视图访问模型属性有点问题。 在我的ItemView中,我有所有的模型属性数据,但当我想在html/模板中输出Javascript Can';具有主干的t访问模型属性。木偶,javascript,backbone.js,coffeescript,marionette,Javascript,Backbone.js,Coffeescript,Marionette,我对使用item/composite视图访问模型属性有点问题。 在我的ItemView中,我有所有的模型属性数据,但当我想在html/模板中输出时,什么都没有 我不知道为什么这不起作用。通常代码和我的一样简单 要点:或以下: index.html: <section> <%= test %> <ul class="thumbnails" id='userslist'></ul> </section> <script ty
时,什么都没有
我不知道为什么这不起作用。通常代码和我的一样简单
要点:或以下:
index.html:
<section>
<%= test %>
<ul class="thumbnails" id='userslist'></ul>
</section>
<script type="text/template" id="usertemplate">
Username: <%= username %>
</script>
console.log打印:
对象{username:“Foo”}
我找到了一个临时解决方案:
-我使用模板代码创建了一个新文件:
// --- members.html
Username: <%= username %>
这个解决方案对我有效。
对于我最初的问题,似乎是当我想要重新映射我的模板原始文本时。
Normaly$('#usertemplate').text()返回模板数据,其中包含所有“”,但不包含“”。
我不知道为什么
如果有人找到了我仍然感兴趣的解决方案:)您真的能够在ItemView的initialize方法中console.log任何内容吗?是的,在每个ItemView initialize方法中,我都可以访问所有属性
// --- members.html
Username: <%= username %>
define [ 'jquery', 'underscore', 'backbone', 'marionette', 'text!templates/us/index.html', 'text!templates/us/members.html' ], ( $, _, Backbone, Marionette, TPL, M) ->
class UserView extends Backbone.Marionette.ItemView
tagName : 'li'
className : 'span2'
template: (serializedModel) =>
_.template M, @model.toJSON()
class UsPageView extends Backbone.Marionette.CompositeView
template : _.template TPL
itemView : UserView
itemViewContainer : "#userslist"
initialize: (options) ->
@collection = options.collection
@collection.fetch()
appendHtml: (cView, iView, idx) ->
cView.$(@itemViewContainer).append iView.el
UsPageView