是否有任何coffeescript特定的技巧,使这看起来更整洁:
index = (->
if segment == 'index'
return 0
else if segment == 'inbox'
return 2
1
)()
Run Code Online (Sandbox Code Playgroud) 我有一个带有许多步骤的ember.js向导控件.
ember模型对象在向导的每个阶段都设置了各种属性.
我可以看到更改视图的唯一方法是使用linkTo helper,如下所示:
{{#linkTo steps.two model}}Step 2{{/linkTo}}
Run Code Online (Sandbox Code Playgroud)
但这对我来说并不好,因为我需要将每个步骤链接到一个动态路径:
@resource "steps", ->
@route "one", {path: 'one/:model_id'}
@route "one", {path: 'two/:model_id'}
#etc.
Run Code Online (Sandbox Code Playgroud)
动态路由不好,因为在向导结束之前不会保存模型.如果我尝试使用transitionTo来传递模型,那么url显然会被搞砸,因为它在模型上调用了tostring.
我更喜欢使用渲染帮助器之类的东西来保持上下文,因为它渲染内容但我认为不可能以这种方式替换整个视图.
有谁能建议更好的方法?
是否可以使用续集来执行这样的查询:
select (select count(*) from users where blah = 'blah') as "users",
(select count(*) from contacts where blah = 'blah') as "contacts"
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用续集一次执行这些查询,但我想同时执行它们.
如何将动态参数传递给组件帮助器。
在生产中,我正在遍历一个json哈希,它将每次以不同的attrs渲染不同的组件。
我在此jsbin中有一个按比例缩小的示例。
我正在返回此json哈希值:
columns: Ember.computed('people.[]', function() {
return this.get('people').map(function(person){
return {
component: 'x-person',
attrs: {
person: person
}
};
});
})
Run Code Online (Sandbox Code Playgroud)
然后,我遍历并尝试将参数传递给组件:
{{#each columns as |column|}}
{{component column.component column.attrs}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
正在创建组件,但未设置属性。
如何正确地将参数传递给组件帮助器?
我有一个表组件,我想从中创建表行组件作为子组件。
var documentsController = function () {};
var documentsComponent = {
template: '<div class="col-lg-12 col-md-12 tableDataContainer">' +
' <table class="table">' +
' <thead>' +
' <tr>' +
' <td>Name</td>' +
' <td>Document Type</td>' +
' </tr>' +
' </thead>' +
' <tr ng-repeat="document in vm.documents">' +
' <document document="document"></document>' +
' </tr>' +
' </table>' +
'</div>',
controller: documentsController,
controllerAs: 'vm',
bindings: {
documents: '<'
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的表行组件:
module.component('documents', documentsComponent);
var documentController = function () {
};
var documentComponent = …Run Code Online (Sandbox Code Playgroud) 在fp-ts中,它们对更高种类的类型有以下解决方法:
export interface HKT<URI, A> {
readonly _URI: URI;
readonly _A: A;
}
Run Code Online (Sandbox Code Playgroud)
可以这样使用:
export interface Foldable<F> {
readonly URI: F;
reduce: <A, B>(fa: HKT<F, A>, b: B, f: (b: B, a: A) => B) => B;
}
Run Code Online (Sandbox Code Playgroud)
成员_URI是_A什么?成员是什么?
我已经升级到 typescript 3.2.2 并且用于编译的这段代码现在没有编译:
export const Heading: React.SFC<HeadingProps> = ({ level, className, tabIndex, children, ...rest }) => {
const Tag = `h${level}`;
return (
<Tag className={cs(className)} {...rest} tabIndex={tabIndex}>
{children}
</Tag>
);
};
Run Code Online (Sandbox Code Playgroud)
随着错误:
类型“IntrinsicAttributes”上不存在属性“tabIndex”。
我有以下项目结构
|_typetests
| |_type.test.ts
|
|
myproj.d.ts
tsconfig.json
Run Code Online (Sandbox Code Playgroud)
我的 tsconfig.json 看起来像这样:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"lib": [
"es6"
],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"types": [
"node",
"mocha"
],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./"
},
"include": [
"types/*.test.ts"
],
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
如果我跑 ./node_modules/.bin/tsc -p . --traceResolution
然后我可以看到:
模块名称“myproj”已成功解析为“/Users/paulcowan/projects/myproj/myproj.d.ts”。========
但是当我通过 mocha 运行以下内容时
./node_modules/.bin/mocha -r ts-node/register types/*.test.ts
Run Code Online (Sandbox Code Playgroud)
Error: Cannot find module 'myproj'
自从升级到打字稿3.5以来,我一直受相同的错误消息困扰,我听不懂:
我有这个反应成分
export const RouteWrapper = function RouteWrapper<
P = { children?: ReactNode },
TRoute extends RouteProps = Route
>(
Wrapper: React.ComponentType<P>,
RouteType: React.ComponentType<RouteProps> = Route,
options: Partial<TRoute> = {},
wrapperProps: P = ({} as unknown) as P
) {
return function RouteWrapperResuslt({
component: RouteComponent,
path,
exact,
...rest
}: RouteWrapperProps<P, Partial<TRoute>>) {
return (
<RouteType
path={path}
exact={exact}
{...options}
component={(props: P) => (
<Wrapper {...wrapperProps || {}}>
<RouteComponent {...rest} {...props} />
</Wrapper>
)}
/>
);
};
};
Run Code Online (Sandbox Code Playgroud)
但是这行错误:
<Wrapper {...(wrapperProps || …Run Code Online (Sandbox Code Playgroud) typescript ×4
ember.js ×2
reactjs ×2
angularjs ×1
coffeescript ×1
css ×1
fp-ts ×1
mocha.js ×1
ruby ×1
sequel ×1
sequel-gem ×1
ts-node ×1