我有一个ArrayController定期更新的.它有一个sorted计算属性,可以保持秩序.我正在尝试使用CollectionView它content绑定到sorted属性的属性,但它不会以正确的顺序呈现它们.演示
我显然做出了错误的假设,即在content和childViews财产之间保持秩序.这样做的正确方法是什么?
把手:
<script type="text/x-handlebars" data-template-name="item">
id {{view.content.id}}
</script>
<script type="text/x-handlebars">
<ul>
{{collection
contentBinding="App.itemController.sorted"
itemViewClass="App.ItemView"
}}
</ul>
</script>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
?App = Ember.Application.create({
ready: function(){
// add a new object with a random id
// every second
setInterval(function(){
var id = Math.round(Math.random() * 100),
obj = Em.Object.create({ id: id });
App.itemController.pushObject(obj);
}, 1000);
}
});
// Collection Item View
App.ItemView = Em.View.extend({
tagName: "li", …Run Code Online (Sandbox Code Playgroud) 我试图通过两个触摸屏点击一个元素,然后单击,通过事件touchStart和click.
如何将这两个事件连接到一个Ember视图?
我试过了:
{{action "itsClicked" on="click touchMove"}}
{{action "itsClicked" on="click, touchMove"}}
{{action "itsClicked" on="click"}} {{action "itsClicked" on="touchMove"}}
我正在构建一个ember.js/rails应用程序.所有车把模板都存储在.js文件中.我想了解当路由器改变状态时它们如何插入到DOM中. 这个部分是什么呢? 如何告诉ember放置模板?
现在我只能将我的模板附加到<body>我有一个jsFiddle这里.
我知道设置rootElementEmber.Application,但我希望应用程序控制页面的其他元素.
把手/ HTML:
<script type="text/x-handlebars" data-template-name="application">
<h2>I'm the content</h2>
<p>This should be inbetween the header & footer</p>
<p><strong>time</strong> {{time}}</p>
</script>
<header>
<h1>Application</h1>
</header>
<article>
<div id="content"></div>
</article>
<footer>
<a href="http://blog.deanbrundage.com" target="_blank">by Dean</a>
</footer>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
window.App = Ember.Application.create();
App.Router = Em.Router.extend({
initialState: 'root.home',
root: Em.Route.extend({
home: Em.Route.extend({
view: App.ApplicationView
})
})
});
App.ApplicationController = Em.Controller.extend({
time: Date()
});
App.ApplicationView = Em.View.extend({
templateName: 'application'
});
App.initialize();
Run Code Online (Sandbox Code Playgroud) 包含最新的emberjs 0.9.7.1 js后,我得到以下错误.
请问,以下错误意味着什么?
错误:
Uncaught Error: assertion failed: You cannot provide a template block if you also specified a templateName
Run Code Online (Sandbox Code Playgroud) 我在我的Ember.js应用程序中有简单的视图,就像这样.每个"content"元素由两个对象组成,第一个和第二个:
{{#each App.myController.content}}
{{view for content.first}}
{{view for content.second}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
我想在另一个手柄模板脚本中单独定义每个内容的视图(以便不必编写两次).如何将第一个和第二个变量传递给视图?
这是一个代码示例,请参阅http://jsfiddle.net/Zm4Xg/5/:
把手:
<script type="text/x-handlebars" data-template-name="contact-view">
<div>{{name}}</div>
<img {{bindAttr src="avatar"}} {{bindAttr alt="name"}}>
</script>
<script type="text/x-handlebars">
{{#each App.contactsController.pair}}
<div class="menu_vertical_group">
{{#with this.first}}
{{view App.contactView}}
{{/with}}
{{#with this.second}}
{{view App.contactView}}
{{/with}}
</div>
{{/each}}
</script>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
App = Ember.Application.create();
App.Contact = Em.Object.extend({
name: null,
avatar: null
});
App.contactView = Ember.View.extend({
templateName: 'contact-view'
});
App.contactsController = Em.ArrayController.create({
content: [],
initData: function(data) {
var contacts = data.map(function(contact) {
return App.Contact.create({
"name": …Run Code Online (Sandbox Code Playgroud) 示例代码:
var Day = Ember.Object.extend({
date:null,
activities:null, // is set to an Em.ArrayProxy in instantiation
historicalSection:function(){
return this.get('activities').filterProperty('inHistoricalSection', true);
}.property('activities').cacheable()
});
Run Code Online (Sandbox Code Playgroud)
当'activities'设置为ArrayProxy时,会计算'historicalSection'计算属性.但是,当'activities'中的ArrayProxy更新(即其长度发生变化)时,'historicalSection'属性不会更新.
有什么想法吗?
我想获取当前登录用户的系统语言.这条线
set lang to do shell script "defaults read NSGlobalDomain AppleLanguages"
Run Code Online (Sandbox Code Playgroud)
返回一个字符串,看起来像
(
en,
de,
ja,
fr,
es,
it,
pt,
"pt-PT",
nl,
sv,
nb,
da,
fi,
ru,
pl,
"zh-Hans",
"zh-Hant",
ko,
ar,
cs,
hu,
tr
)
Run Code Online (Sandbox Code Playgroud)
返回用户语言,但我怎样才能得到这个'数组'的第一个?是否有可能将此解析为数组获取其第一个值?
有人可以看看这个:http://jsfiddle.net/tur9b/9/
这是一个简单的有序列表.您可以通过单击名称来删除列表条目.
IE(在IE9中测试)显示出奇怪的行为.目前我不知道那里的错误是什么.
ember.js ×8
javascript ×2
applescript ×1
dom ×1
ember-data ×1
macos ×1
templates ×1
terminal ×1
view ×1