错误会显示一条消息,并阻止提交表单,而警告仅显示一条消息。
我错误地假设将支持异步验证错误和警告,但事实并非如此。
不幸的是,异步验证并不能正式发出警告。
目前,要摆脱使用redux-forms会花费大量的精力,因此我试图找到一种足够的解决方法。
一种解决方案是手动向表单添加警告。如果可能的话,那么异步验证通常可以照常执行,但是要在最后设置警告,而不是提供预期的错误对象。
但是我看了看文档,似乎没有办法手动添加警告或错误。
您可以将验证函数传递到特定字段或整个表单,然后将这些验证函数根据需要由redux-forms调用。
看来不能直接设置错误和警告,但是也许我们可以手动触发特定字段的重新验证?
不,显然目前还不可能。
总结一下:
任何建议,见解或纠正都非常欢迎。
如果我在任何这些要点上错了,我将非常高兴!
如果找不到解决方案,那么我将寻找一个替代库,并且将开始繁重的工作,摆脱redux-forms。
这无疑很好地提醒了我自己的假设愚蠢。
我正在研究一些代码来平衡括号,这个问题证明对算法最有用.
我用我的第一语言(PHP)实现它,但我正在学习Scala并尝试转换代码.
这是我的PHP代码:
function balanced($string) {
return isBalanced($string, "");
}
function isBalanced($chars, $stack) {
if (!strlen($chars))
return empty($stack);
switch ($chars[0]) {
case '(':
// prepend stack with '(', move to next character
return isBalanced(substr($chars, 1), $chars[0] . $stack);
case ')':
// if '(' seen previously, shift stack, move to next character
return !empty($stack) && isBalanced(substr($chars, 1), substr($stack, 1));
default:
// do nothing to stack, move to next character
return isBalanced(substr($chars, 1), $stack);
}
}
Run Code Online (Sandbox Code Playgroud)
我测试了这个,它有效.但是,当我将其转换为Scala时,它在平衡字符串上失败.
我的Scala代码:
object Main …Run Code Online (Sandbox Code Playgroud) 我正在使用java.lang.IllegalArgumentException: No value supplied for key:我的Clojure代码.
我知道当我试图在作为参数传递的映射中对密钥进行解构时会发生这种情况.
然而,奇怪的是,这个函数已经很好地工作了很长时间,具有相同的数据.唯一似乎不同的是我现在如何导入该功能
这是错误:
Caused by: java.lang.IllegalArgumentException: No value supplied for key:
{:style {:color [255 150 150 255], :stroke-weight 2}, :points [[-1 0] [0 -1] [1 0] [0 1] [-1 0]]}
Run Code Online (Sandbox Code Playgroud)
而这就是抛出它的功能.
(defn scale
[val {:keys [style points]}]
{:style style
:points (scale-shape val points)})
Run Code Online (Sandbox Code Playgroud)
换句话说,我要求地图包含被调用的键style,points并且它被赋予一个包含被称为style和的键的映射points.
这段代码已经好几个月了.
不同之处在于我现在使用导入的sshapes/scale位置调用它sshapes:
(:require [patterning.sshapes :as sshapes])
Run Code Online (Sandbox Code Playgroud)
而之前我只是把它称为scale使用扩展名进入命名空间的地方
(:require [patterning.sshapes :refer :all])
Run Code Online (Sandbox Code Playgroud)
这会导致那种错误吗?
通过SPL迭代器递归扫描目录的标准方法是:
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
print $file->getPathname() . PHP_EOL;
}
Run Code Online (Sandbox Code Playgroud)
我想要一组可组合的过滤器应用于我的递归文件搜索.我正在使用a RecursiveDirectoryIterator来扫描目录结构.
我想在我的目录结构中应用多个过滤器.
我的设置代码:
$filters = new FilterRuleset(
new RecursiveDirectoryIterator($path)
);
$filters->addFilter(new FilterLapsedDirs);
$filters->addFilter(new IncludeExtension('wav'));
$files = new RecursiveIteratorIterator(
$filters, RecursiveIteratorIterator::CHILD_FIRST
);
Run Code Online (Sandbox Code Playgroud)
我以为我可以使用规则集来应用N个过滤器:
class FilterRuleset extends RecursiveFilterIterator {
private $filters = array();
public function addFilter($filter) {
$this->filters[] = $filter;
}
public function accept() {
$file = $this->current();
foreach ($this->filters as $filter) {
if (!$filter->accept($file)) {
return false;
}
}
return …Run Code Online (Sandbox Code Playgroud) 此代码似乎仅在Firefox中有效。Safari和Opera不喜欢它:
alert($("<body>").css("background-color"));
Run Code Online (Sandbox Code Playgroud)
我也尝试过其他不太成功的方法。
alert(document.getElementsByTagName("body")[0].styles.backgroundColor);
alert(document.body.styles.backgroundColor);
Run Code Online (Sandbox Code Playgroud)
我已经在Mac上测试过这些浏览器-尚未在IE中测试过。有任何想法吗?
如本博文中所述,您可以this在Javascript中设置匿名函数的范围.
在AJAX请求this的匿名函数调用中是否有更优雅的方法作用success(即不使用that)?
例如:
var Foo = {
bar: function(id) {
var that = this;
$.ajax({
url: "www.somedomain.com/ajax_handler",
success: function(data) {
that._updateDiv(id, data);
}
});
},
_updateDiv: function(id, data) {
$(id).innerHTML = data;
}
};
var foo = new Foo;
foo.bar('mydiv');
Run Code Online (Sandbox Code Playgroud)
使用调用但仍必须命名父对象范围that.
success: function(data) {
(function() {
this._updateDiv(id, data);
}).call(that);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP SoapClient来使用SOAP服务,但是收到的错误是SOAP服务无法看到我的参数.
<tns:GenericSearchResponse xmlns:tns="http://.../1.0">
<tns:Status>
<tns:StatusCode>1</tns:StatusCode>
<tns:StatusMessage>Invalid calling system</tns:StatusMessage>
</tns:Status>
</tns:GenericSearchResponse>
Run Code Online (Sandbox Code Playgroud)
XML PHP的SoapClient为SOAP调用发送:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://.../1.0">
<SOAP-ENV:Body>
<ns1:GenericSearchRequest>
<UniqueIdentifier>12345678</UniqueIdentifier>
<CallingSystem>WEB</CallingSystem>
</ns1:GenericSearchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
我最初使用soap-ui,在使用相同的WSDL时成功运行.XML soap-ui发送呼叫:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://.../1.0">
<SOAP-ENV:Body>
<ns1:GenericSearchRequest>
<ns1:UniqueIdentifier>12345678</ns1:UniqueIdentifier>
<ns1:CallingSystem>WEB</ns1:CallingSystem>
</ns1:GenericSearchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
不同的是UniqueIdentifier和CallingSystem参数ns1在soap-ui请求中作为前缀.
我已尝试将传递SoapVar对象用于SoapClient调用,但这不会增加参数标记并为其添加前缀ns1.
我知道这WEB是一个有效的CallingSystem值,因为XSD指定它,并且它在使用soap-ui时有效.
我目前的SoapClient代码:
try {
$client = new SoapClient($wsdl, array('trace' => 1));
$query = new stdClass;
$query->UniqueIdentifier = $id;
$query->CallingSystem = 'WEB';
$response = $client->GenericUniqueIdentifierSearch($query); …Run Code Online (Sandbox Code Playgroud) 谈论在第一个障碍下跌.我的测试脚本:
<?php
require_once('PHPUnit/Framework.php');
class TransferResponseTest extends PHPUnit_TestCase {
...
}
Run Code Online (Sandbox Code Playgroud)
运行我的测试用例:
$ phpunit TransferResponseTest
Fatal error: Class 'PHPUnit_TestCase' not found in
/Volumes/Data/greg/code/syndicate/tests/TransferResponseTest.php on line 5
$ php -i | grep include_path
include_path => .:/usr/lib/php => .:/usr/lib/php
$ ls -l /usr/lib/php/PHPUnit/
total 8
drwxr-xr-x 16 root wheel 544 27 Mar 19:03 Extensions
drwxr-xr-x 28 root wheel 952 27 Mar 19:03 Framework
-rw-r--r-- 1 root wheel 3193 27 Mar 19:03 Framework.php
drwxr-xr-x 8 root wheel 272 27 Mar 19:03 Runner
drwxr-xr-x 5 …Run Code Online (Sandbox Code Playgroud) 我正在尝试用ring和compojure学习clojure web开发,我对compojure.route/resourcesand 的用法有点不清楚ring.middleware.resource/wrap-resource.
我已经看过了API文档,以及两者的来源compojure.route和ring.middleware.resource.但是,我仍然不清楚是否需要使用compojure.route/resources路由和ring.middleware.resource/wrap-resource中间件,或者是否compojure.route/resources需要处理所有事情.
还是优化问题?在使用中,wrap-resource避免使用组件路由开销?任何见解将不胜感激.
我刚开始用Qt.尽管今天晚上花了一些时间,但我仍在努力将我的UI设置代码移出main它自己的类.
#include <QtGui>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget *window = new QWidget;
QLabel *hw = new QLabel(QObject::tr("Hello World!"));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(hw);
window->setLayout(layout);
window->show();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试创建自己的类并传递window给它但遇到编译错误.
main.cpp中:
#include <QtGui>
#include "hworld.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QDialog *hWorld = new hWorld;
hWorld->show();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
hworld.h:
#ifndef HWORLD_H
#define HWORLD_H
#include <QtGui>
class hWorld : public QDialog {
Q_OBJECT
public:
hWorld(QWidget *parent = …Run Code Online (Sandbox Code Playgroud)