我正在为MobX 看这个小提琴,我也看到了这两种在ES6其他地方定义React Components的方法,比如Dan Abramov的egghead redux视频系列.
@observer
class TodoListView extends Component {
render() {
return <div>
<ul>
{this.props.todoList.todos.map(todo =>
<TodoView todo={todo} key={todo.id} />
)}
</ul>
Tasks left: {this.props.todoList.unfinishedTodoCount}
</div>
}
}
const TodoView = observer(({todo}) =>
<li>
<input
type="checkbox"
checked={todo.finished}
onClick={() => todo.finished = !todo.finished}
/>
<input
type="text"
value={todo.title}
onChange={ e => todo.title = e.target.value } />
</li>
);
Run Code Online (Sandbox Code Playgroud)
我的问题是,什么时候适合使用每种类型?
似乎更简单的组件能够使用更简单的语法,但我希望遵循规则或准则.
谢谢!
我无法让PIL放大图像.大图像缩小得很好,但小图像不会变大.
# get the ratio of the change in height of this image using the
# by dividing the height of the first image
s = h / float(image.size[1])
# calculate the change in dimension of the new image
new_size = tuple([int(x*s) for x in image.size])
# if this image height is larger than the image we are sizing to
if image.size[1] > h:
# make a thumbnail of the image using the new image size
image.thumbnail(new_size)
by = "thumbnailed" …Run Code Online (Sandbox Code Playgroud) 我正在使用angular-ui-router在bootstrap和angular中编写一个下拉导航.当链接有下拉列表时,链接应为空白.但是,如果我将一条空白路径传递给ui-sref,我会收到错误消息.
这是一段代码片段:
<ul class="dropdown-menu">
<li ng-repeat="button in buttons" id="foo" ng-class="{'dropdown-submenu': $index=button.hasLinks}" >
<a ui-sref="{{button.route}}" title="{{ button.text }} Tab" class="{ dropdown-toggle: button.links }" data-toggle="dropdown">
<i class="icon icon-{{ button.icon }}"></i> {{ button.text }}
</a>
<ul class="dropdown-menu">
<li ng-repeat="link in button.links">
<a ng-href="{{ link.route }}" title="{{ link.text }} Tab">
{{ link.text }}
</a>
</li>
</ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 只是想知道在python中是否有更聪明,更短的方式来编写它.
y = False
x = not y
Run Code Online (Sandbox Code Playgroud)
在javascript中我会:
y = false,
x = !y
Run Code Online (Sandbox Code Playgroud)
谢谢!