我试着设置这样的路由
...
url: '/view/:inboxId?'
...
Run Code Online (Sandbox Code Playgroud)
但是Angular会抛出这个错误:
Error: Invalid parameter name '' in pattern '/view/:inboxId?'
Run Code Online (Sandbox Code Playgroud)
所以基本上我必须设置两种不同的状态:
state('view', {
url: '/view/:inboxId',
templateUrl: 'templates/view.html',
controller: 'viewCtrl'
}).
state('view_root', {
url: '/view',
templateUrl: 'templates/view.html',
controller: 'viewCtrl'
})
Run Code Online (Sandbox Code Playgroud)
有没有办法将这些状态合二为一?
我的路线设置如下:
<Route path="/chat/:id" component={Chat} />
<Route path="/chat/new" component={NewChat} />
Run Code Online (Sandbox Code Playgroud)
当我去chat/new它也显示{Chat}.NewChat我去的时候有没有办法专门打电话/chat/new?
如何通过 $.ajax 将额外的变量传递给 post.php?
我的第一个变量是
var form_data = new FormData($(this)[0])
Run Code Online (Sandbox Code Playgroud)
我可以单独传递它,但是如果我想添加另一个变量并创建一个数组
data {
"form_data": form_data,
"name": "hello"
}
Run Code Online (Sandbox Code Playgroud)
它不起作用。
我目前的代码:
$(document).ready(function() {
$("form#data").submit(function(){
var form_data = new FormData($(this)[0]);
$.ajax({
url: 'post.php',
type: 'POST',
data: form_data,
success: function (data) {
$('#result').html(data);
},
contentType: false,
processData: false
});
return false;
});
});
<div id="result"></div>
<form id="data" method="post" enctype="multipart/form-data">
<input name="file" type="file" />
<button>Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud) 我正在针对以下组件运行测试:
const App: React.FC<RouteComponentProps> = ({ history, location, match }) => { ... }
Run Code Online (Sandbox Code Playgroud)
所有的测试都通过了,但是我收到了这个警告:
const { getByText, debug } = render(<MemoryRouter><Route><App/></Route></MemoryRouter>);
Type '{}' is missing the following properties from type 'RouteComponentProps<{}, StaticContext, {}>': history, location, match(2739)
Run Code Online (Sandbox Code Playgroud)
我的印象是<MemoryRouter>&<Route>会提供<App/>缺少的属性......
我有一个基本的XMPP客户端在strophe.js上工作.
在登录时我创建了诸如的处理程序
connect = new Strophe.Connection('http://localhost/http-bind');
...
...
connect.addHandler(on_message, null, "message", "chat");
connect.addHandler(on_presence, null, "presence");
...
...
Run Code Online (Sandbox Code Playgroud)
然后我"倾听"那些
function on_presence(presence) {
// handling presence
}
function on_message(presence) {
// handling presence
}
Run Code Online (Sandbox Code Playgroud)
所以我想把它"转换"成AngularJS.第一部分非常简单.我有一个控制器,可以正常处理登录部分:
angular.module('app').controller('loginCtrl', function($scope) {
connect = new Strophe.Connection('http://website.com/http-bind');
connect.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
connect.addHandler(on_message, null, "message", "chat");
connect.addHandler(on_presence, null, "presence");
}
}
})
Run Code Online (Sandbox Code Playgroud)
但是,我如何实际开始在我所拥有的所有控制器的角度上下文中监听这些事件(on_message,on_presence).
我有多个<select id="direction_X"></select>由我的PHP脚本生成.X是它的ID.我试图通过这样做来选择这些元素:
$('select[id*="direction_"]').live('change', function() {
selected = $('select[id*="direction_"] option:selected');
option_ID = $(selected).val();
console.log(option_ID);
}
Run Code Online (Sandbox Code Playgroud)
事实上,当我使用时,我正在获取option_ID,但如果我尝试使用任何其他的,我将始终获得相同的option_ID.
如果你先点击它,它会给你(一个空字符串),当你点击之后它会给你第一个正确的ID
我正在尝试使用以下查询同时搜索 wp_post 和 wp_postmeta:
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'City'
AND $wpdb->postmeta.meta_value = 'Vancouver'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'talents'
ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我搜索以 City=Vancouver 作为元字段的帖子。但是,我如何再添加一项条件,以免将不列颠哥伦比亚省温哥华市和华盛顿州温哥华市放在一起?
像这样:
AND ($wpdb->postmeta.meta_key = 'Country'
AND $wpdb->postmeta.meta_value = 'Canada')
AND ($wpdb->postmeta.meta_key = 'City'
AND $wpdb->postmeta.meta_value = 'Vancouver')
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有几个mysql表:多伦多,温哥华,蒙特利尔等...我正在使用数据库类来处理它们,例如.
$data = DB::select('select * from toronto where id = ?', array($id));
Run Code Online (Sandbox Code Playgroud)
我想要做的是开始使用Eloquent.我是Laravel的新手,只是想知道是否有可能让一个模型与几个表一起工作,如:
class City extends Eloquent {
protected $table_a = 'toronto';
protected $table_b = 'vancouver';
protected $table_c = 'montreal';
}
Run Code Online (Sandbox Code Playgroud) store.subscribe( () => {} ) 是观察 Redux 商店变化的唯一方法吗?
我异步获取我的用户,当应用加载时,用户存储很可能是空的,所以我必须做这样的事情:
store.subscribe( () => {
var users = store.getState().users;
if( users.length > 0 ) {
this.setState({ ... })
}
});
Run Code Online (Sandbox Code Playgroud)
现在我有 3 或 4 个组件,我必须在每个组件中使用相同的逻辑。我的问题:这个问题有更优雅的解决方案吗?在“全球层面”聆听 Redux 变化的某种方式?
所以我的设置很简单
样式指南.config.js
module.exports = {
components: 'src/components/**/*.js',
require: [
path.join(__dirname, 'node_modules/bootstrap/scss/bootstrap.scss')
]
};
Run Code Online (Sandbox Code Playgroud)
每当我运行 npm run styleguide 时,我都会收到此错误:
模块解析失败:意外字符@您可能需要合适的加载程序来处理此文件类型。
bootstrap.scss看起来像这样:
@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/mixins";
...
...
Run Code Online (Sandbox Code Playgroud)
我知道我需要添加 SASS-loader,但我发现的示例使用不同的上下文,所以我还不能真正弄清楚它们。
ps 当我运行应用程序本身时,SASS 在 React Styleguide 之外工作,而不是 styleguide。
有问题的路线是这样的: chats/5de3e056c022b2b3252dab43/messages 但我似乎无法找到一种相对简单的方法来检索 ID (5de3e056c022b2b3252dab43) 并且无处可寻(是的,我可以解析那里的网址,但我希望更好的方法 - 类似于 req.params.id)
基本上这就是 CTX 对象的样子:
{
"request": {
"method": "GET",
"url": "/chats/5de3e056c022b2b3252dab43/messages",
"header": {
"authorization": "Bearer ******",
"user-agent": "PostmanRuntime/7.19.0",
"accept": "*/*",
"cache-control": "no-cache",
"postman-token": "e320fdc2-81a5-4f36-a4d1-ec621188e27d",
"host": "localhost:1337",
"accept-encoding": "gzip, deflate",
"connection": "keep-alive"
}
},
"response": {
"status": 200,
"message": "OK",
"header": {
"vary": "Origin",
"content-security-policy": "img-src 'self' http:; block-all-mixed-content",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "1; mode=block",
"content-type": "application/json; charset=utf-8",
"x-powered-by": "Strapi <strapi.io>"
}
},
"app": {
"subdomainOffset": 2,
"proxy": false,
"env": "development" …Run Code Online (Sandbox Code Playgroud)