我的枚举看起来像:
object ContentType extends Enumeration {
type ContentType = Value
val BlogPost, KB, Link = Value
}
Run Code Online (Sandbox Code Playgroud)
现在我想使用此枚举创建一个下拉列表.
@helper.select(field = ContentForm("contentType"), options = @contentTypes)
Run Code Online (Sandbox Code Playgroud)
Play有一个@helper.select需要序列的方法,所以我添加了一个序列,我将传递给我的视图页面:
val contentTypes: Seq[(Int, String)] = ...
Run Code Online (Sandbox Code Playgroud)
如何从ContentType枚举中初始化或创建此序列?
更新
对不起,它必须是Seq [(String,String)]类型
我有一个方法,我想返回Future[Vector[user]].
该方法userLocationService.getUserLocationsInList将返回一个Future[Vector[UserLocation]].
UserLocation看起来像这样:
case class UserLocation(id: Int, locationId: Int, userId: Int)
def getUsersInLocation(locationIdList: Set[Int]): Future[Vector[User]] = {
userLocationService.getUserLocationsInList(locationIdList).map{
userLocations =>
// ????????????
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个方法,返回基于UserId的单个用户,如:
userService.getById(userId: Int): Future[User]
Run Code Online (Sandbox Code Playgroud)
如何根据上述内容构建Future [Vector [User]]?
我在尝试编写返回Future [Map [Int,Long]]的方法时遇到问题.
我正在进行一些迭代,回到未来[未来[..]].所以我尝试了flatMap身份.
请参阅下面的我现在收到的代码和错误消息.我不知道此刻发生了什么.
def aggregate(permissions: Vector[Permission]): Map[Int, Long]
def calculate(roleProfile: RoleProfile): Future[Map[Int, Long]] = {
val roleIds = roleProfile.roles.map(r => r.id)
db.run(permissionDao.getByRoles(roleIds.toList)).map {
permissions =>
aggregate(permissions)
}
}
def generate(roleGroupId: Int): Future[Map[Int, Long]] = {
for {
roleGroup <- roleGroupService.getById(roleGroupId)
roles <- roleGroupService.getRolesByGroupId(roleGroupId)
} yield {
calculate(RoleProfile(roleGroup.get.id, roles.toSet)) //flatMap identity
}
}
Run Code Online (Sandbox Code Playgroud)
我收到方法'计算'的错误消息:
type mismatch;
[error] found : scala.concurrent.Future[Map[Int,Long]]
[error] required: Map[Int,Long]
[error] calculate(RoleProfile(roleGroup.get.id, roles.toSet)) //flatMap identity
Run Code Online (Sandbox Code Playgroud)
现在,如果删除'flatMap identity'的注释,我会收到此错误:
type mismatch;
[error] found : Map[Int,Long] => Map[Int,Long]
[error] …Run Code Online (Sandbox Code Playgroud) 以下工作正常:
def show(id: Int) = myAction asyc {
for {
users <- userService.getAll()
locations <- locationService.getByUsers(users)
} yield {
Ok("hi")
}
}
Run Code Online (Sandbox Code Playgroud)
但如果我这样做:
for {
users <- userService.getAll()
locations <- locationService.getByUsers(users)
} yield {
for {
f1 <- ...
f2 <- ....
} yield {
Ok("hi")
}
}
Run Code Online (Sandbox Code Playgroud)
我收到类型不匹配错误:
found : scala.concurrent.Future[play.api.mvc.Result]
[error] required: play.api.mvc.Result
[error] f1 <- ....
Run Code Online (Sandbox Code Playgroud)
希望有人能为我解释一下.
我有一个我需要制作抽象的演员,因为它被用作许多地方使用的常见模式.
abstract class SomeActor(.....) extends Actor with ActorLogging {
def receive = {
case Message1 =>
case Message2 =>
case Message3 =>
}
}
Run Code Online (Sandbox Code Playgroud)
现在说我需要自定义一个actor实现来处理Message2的逻辑,我有什么选择才能实现这个目的?
我想创建一个特征,但是我希望所有使用这个特征的类都有一些特定的类:
trait SomeHelper {
def homeUrl(): String =
s"$website.url"
}
class Foo(website: Website) extends SomeHelper {
val hello = homeUrl + "/hello"
}
Run Code Online (Sandbox Code Playgroud)
如何要求特质用户拥有网站类?
只是学习灵丹妙药,我想了解为什么灵药选择如此冗长,并根据辅助方法做事:
String.upcase(name)
Run Code Online (Sandbox Code Playgroud)
而不是这样做:
name.upcase
Run Code Online (Sandbox Code Playgroud)
在Scala中你可以做到name.toUpperCase,它仍然会返回一个新变量,因为它是不可变的.
无论如何,只是试图理解这种方法的原因,因为我确信这是一个原因.
如果我安全地改变我的演员内部的可变地图/队列,我有点困惑.
有人能告诉我这段代码是否是线程安全且正确的?
class SomeActor extends Actor {
val userQ = mutable.Queue.empty[User]
val tranQ = mutable.Map.empty[Int, Transaction]
def receive = {
case Blank1 =>
if(userQ.isEmpty)
userQ ++= getNewUsers()
case Blank2 =>
val companyProfile = for {
company <- api.getCompany() // Future[Company]
location <- api.getLoc() // Future[Location]
} yield CompanyProfile(company, location)
companyProfile.map { cp =>
tranQ += cp.id -> cp.transaction // tranQ mutatated here
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于我用期货改变了tranQ,这样安全吗?
我的理解是每个演员的消息都是以连续的方式处理的,所以虽然可能不赞成我可以像这样使用可变状态.
我很困惑,如果在未来的电话中使用它,比如tranQ是否安全.
我正在尝试在我的类上添加@DragDropContext装饰器,但是当我在浏览器中加载它时出现错误.
我的组件看起来像:
import React from 'react';
import Link from 'react-router-dom';
import { connect } from 'react-redux';
import { DragDropContext } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import PropTypes from 'prop-types';
@DragDropContext(HTML5Backend)
class UserShowView extends React.Component {
}
export default connect(mapStateToProps)(UserShowView);
Run Code Online (Sandbox Code Playgroud)
这是chrome控制台中的错误:
bundle.js:977未捕获错误:期望后端成为函数或导出默认函数的ES6模块.阅读更多:http: //react-dnd.github.io/react-dnd/docs-drag-drop-context.html
我的babelrc文件:
{
"plugins": ["transform-decorators-legacy"],
"presets": ["react", "es2015", "stage-0"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
packages.json:
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node tools/srcServer.js",
"test": …Run Code Online (Sandbox Code Playgroud) 我的布局有:
//= require activestorage
Run Code Online (Sandbox Code Playgroud)
现在在我的 jQuery 中,我试图引用 DirectUpload 类:
// Instantiate the DirectUploader object
const upload = new DirectUpload(file, url)
Run Code Online (Sandbox Code Playgroud)
直接上传类在这里:https : //github.com/rails/rails/blob/b2eb1d1c55a59fee1e6c4cba7030d8ceb524267c/activestorage/app/javascript/activestorage/direct_upload.js
我目前收到此错误:
未捕获的 ReferenceError:DirectUpload 未在 new:210 处定义