是否有可能在木偶中有一个复合视图,里面有不同的项目视图?例如:
var myCompositeView = Backbone.Marionette.CompositeView.extend({
template: Handlebars.compile(myTemplate),
itemView: myView, // I want different views, not just myView
initialize: function(){
this.collection = this.model.views;
},
appendHtml: function(collectionView, itemView){
collectionView.$('.container').append(itemView.el);
}
Run Code Online (Sandbox Code Playgroud)
});
基本上,根据集合中的模型,我想创建一个特定的视图.
我有这样的链接:
<a href="my:stuff">My Link</a>
<a href="other:stuff">My Link</a>
<a href="test:stuff">My Link</a>
<a href="test:stuff">My Link</a>
Run Code Online (Sandbox Code Playgroud)
我想选择href不以" test" 开头的链接
我尝试了以下但它们似乎不起作用:
$('a[href!^="test"]')
$('a:not([href^="test"]')
Run Code Online (Sandbox Code Playgroud)
我不想使用$.filter或类似的东西.有没有办法单独使用选择器?
我正在使用组合模式进行反应。例如,我有这个简单的组件:
class Simple extends React.Component {
render() {
return <div>{this.props.text}</div>;
}
}
Simple.propTypes = {
text: React.PropTypes.string.isRequired
};
Run Code Online (Sandbox Code Playgroud)
现在,我有了这个增强的组件:
class Enhanced extends React.Component {
render() {
return (
<div>
<div>Hi, I'm the enhanced version</div>
<Simple {...this.props} />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我如何指定增强组件的 proptypes?我可以这样做:
Enhanced.propTypes = {
text: React.PropTypes.string.isRequired
};
Run Code Online (Sandbox Code Playgroud)
但这不好,因为我必须列出Simple组件的所有道具,并且每当我更改这些道具时,我都必须更改它们Enhanced
如果我想创建一个新分支,我会这样做:
git checkout -b new-branch
Run Code Online (Sandbox Code Playgroud)
然而,有时这个分支已经存在,例如:
fatal: A branch named 'new-branch' already exists.
Run Code Online (Sandbox Code Playgroud)
有比执行以下操作更简单的方法吗?
git branch -D new-branch
git checkout -b new-branch
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,但它不起作用:
git checkout -b new-branch --force
Run Code Online (Sandbox Code Playgroud) 如何在没有特定数据属性的情况下找到所有元素?
我试过了:
$list.find('li:not([data-stuff])');
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
是否有更好的方法在数组中的每个项目上调用方法:
_.each(items, function(item) {
item.method();
});
Run Code Online (Sandbox Code Playgroud)
在Scala中,您可以执行以下操作:
items.foreach(_.method())
Run Code Online (Sandbox Code Playgroud)
想知道javascript中是否有类似的东西
假设我的html看起来像这样:
<div class="container">
<... some html here ...>
</div>
Run Code Online (Sandbox Code Playgroud)
我想得到第一个直接的孩子.container.
我能做到.container > div:first-child但是假设它是一个div并非总是如此.
javascript ×3
jquery ×3
backbone.js ×1
branch ×1
css ×1
find ×1
git ×1
github ×1
html ×1
lodash ×1
marionette ×1
reactjs ×1