我正在创建一个用户可以设计自己的表单的应用程序.例如,指定字段的名称以及应包含哪些其他列的详细信息.
该组件在此处作为JSFiddle提供.
我的初始状态如下:
var DynamicForm = React.createClass({
getInitialState: function() {
var items = {};
items[1] = { name: 'field 1', populate_at: 'web_start',
same_as: 'customer_name',
autocomplete_from: 'customer_name', title: '' };
items[2] = { name: 'field 2', populate_at: 'web_end',
same_as: 'user_name',
autocomplete_from: 'user_name', title: '' };
return { items };
},
render: function() {
var _this = this;
return (
<div>
{ Object.keys(this.state.items).map(function (key) {
var item = _this.state.items[key];
return (
<div>
<PopulateAtCheckboxes this={this}
checked={item.populate_at} id={key}
populate_at={data.populate_at} />
</div>
); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试迭代哈希中的所有键,但是没有从循环返回输出.console.log()
按预期输出.知道为什么JSX没有返回并输出正确吗?
var DynamicForm = React.createClass({
getInitialState: function() {
var items = {};
items[1] = { name: '', populate_at: '', same_as: '',
autocomplete_from: '', title: '' };
items[2] = { name: '', populate_at: '', same_as: '',
autocomplete_from: '', title: '' };
return { items };
},
render: function() {
return (
<div>
// {this.state.items.map(function(object, i){
// ^ This worked previously when items was an array.
{ Object.keys(this.state.items).forEach(function (key) {
console.log('key: ', key); // Returns key: 1 and key: 2 …
Run Code Online (Sandbox Code Playgroud) 在这里我尝试设置state.autocomplete
为'hello'然后打印它,但状态似乎是null.当我刚刚使用状态更新时,怎么会这样setState
?data
被设置为全局变量.
var data = {
populate_at: ['web_start', 'web_end'],
autocomplete_from: ['customer_name', 'customer_address']
};
var AutocompleteFromCheckboxes = React.createClass({
handleChange: function(e) {
this.setState( { autocomplete_from: 'event.target.value' } );
console.log('autocompleteFrom state: ', this.state.autocomplete_from);
// ^ => Uncaught TypeError: Cannot read property 'autocomplete_from' of null
return 1;
},
render: function() {
var autocompleteFrom = this.props.autocomplete_from.map(function(value) {
return (
<label for={value}>
<input type="checkbox" name={value} value="{value}"
onChange={this.handleChange.bind(this)}
ref="autocomplete-from"/>
{value}
</label>
);
}, this);
return (
<div className="autocomplete-from">
{autocompleteFrom}
</div>
);
} …
Run Code Online (Sandbox Code Playgroud) 该文档指出的是
要从一个或多个文件创建机密,请使用--from-file.只要文件包含键值对,就可以指定任何纯文本格式的文件,例如.txt或.env.
.测试秘密
NAME=martin
GENDER=male
Run Code Online (Sandbox Code Playgroud)
测试基于我的.test-secret文件创建秘密.
kubectl create secret generic person --from-file .test-secret -o yml
$ kubectl get secret person -o yaml
apiVersion: v1
data:
.test-secret: TkFNRT1tYXJ0aW4KR0VOREVSPW1hbGUK
kind: Secret
metadata:
creationTimestamp: 2018-07-19T09:23:05Z
name: person
namespace: default
resourceVersion: "229992"
selfLink: /api/v1/namespaces/default/secrets/person
uid: 579198ab-8b35-11e8-8895-42010a840008
type: Opaque
Run Code Online (Sandbox Code Playgroud)
是否可以读取这样的键/值列表?甚至可以从.env
文件中这样做吗?kubectl get pods
返回CreateContainerConfigError
我-app.yml
77 - name: NAME
78 valueFrom:
79 secretKeyRef:
80 name: person
81 key: NAME
Run Code Online (Sandbox Code Playgroud) 我正在使用docker-compose来启动3个应该在副本集中的MongoDB服务器.
我首先启动3个MongoDB服务器,然后配置副本集.这就是我在bash脚本中执行副本集配置的方法:
mongo --host 127.0.0.1:27017 <<EOF
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "127.0.0.1:27017",
"priority": 1
},
// snip...
]
};
rs.initiate(cfg);
rs.reconfig(cfg)
EOF
Run Code Online (Sandbox Code Playgroud)
在这里,我试图使用docker-compose复制配置副本集.
# docker-compose.yml
mongosetup:
image: mongo:3.0
links:
- mongo1:mongo1
command: echo 'var cfg = { "_id": "rs", "version": 1, "members": [ { "_id": 0, "host": "127.0.0.1:27017", "priority": 1 }, { "_id": 1, "host": "mongo2:27017", "priority": 1 },{ "_id": 2, "host": "mongo2:27017", "priority": 1 } ] …
Run Code Online (Sandbox Code Playgroud) mongodb elasticsearch docker elasticsearch-plugin docker-compose
我正在研究的本机反应项目已经使用react-native-device-info.当我尝试添加Android-${DeviceInfo.getUniqueID()}
到请求中的标头时,我收到此错误:
{ TypeError: DeviceInfo.getUniqueID is not a function
at makeRequest (~/code/rn/src/services/api-client.js:46:39)
Run Code Online (Sandbox Code Playgroud)
怎么可能?我在它使用的文件的顶部像这样导入它.
import * as DeviceInfo from 'react-native-device-info';
Run Code Online (Sandbox Code Playgroud)
如果我将import语句更改为import DeviceInfo from 'react-native-device-info';
,那么我收到此错误:
TypeError: _reactNativeDeviceInfo2.default.getUniqueID is not a function
export function makeRequest(endpoint, method, token, csrfToken = null, body = null) {
const config = {
method,
credentials: 'same-origin',
headers: {
Applikasjon: 'KONSERNAPP',
Accept: 'application/json',
'X-App-Version': `Android-${DeviceInfo.getUniqueID()}`,
'Content-Type': 'application/json',
token,
},
timeout: 120000,
};
Run Code Online (Sandbox Code Playgroud) 在接受用户凭证后,我获取了承载令牌[1]并更新了默认头:
$http.defaults.headers.common.Authorization = "Bearer #{data.access_token}"
Run Code Online (Sandbox Code Playgroud)
这是在$ scope.signIn()方法的末尾完成的.这些令牌在整个会话期间是否会持久存在,还是应该使用其他技术?
[1] https://github.com/doorkeeper-gem/doorkeeper/wiki/Client-Credentials-flow
app.run run = ($http, session) ->
token = session.get('token')
$http.defaults.headers.common['Authorization'] = token
Run Code Online (Sandbox Code Playgroud) 我可以同步我的 Gmail 收件箱,但发送的文件夹不起作用。
这是我的.mbsyncrc
IMAPStore martinstabenfeldt-remote
Account martinstabenfeldt
MaildirStore martinstabenfeldt-local
Path ~/.mail/martinstabenfeldt/
INBOX ~/.mail/martinstabenfeldt/INBOX
Channel martinstabenfeldt
Master :martinstabenfeldt-remote:
Slave :martinstabenfeldt-local:
Patterns *
# Automatically create missing mailboxes, both locally and on the server
Create Both
# Save the synchronization state files in the relevant directory
SyncState *
Channel martinstabenfeldt-inbox
Master ":martinstabenfeldt-remote:INBOX"
Slave ":martinstabenfeldt-local:INBOX"
Channel martinstabenfeldt-sent
Master ":martinstabenfeldt-remote:[Gmail]/Sent Mail"
Slave ":martinstabenfeldt-local:sent"
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
$ mbsync --verbose martinstabenfeldt-sent
Logging in...
Opening master box [Gmail]/Sent Mail...
Opening slave box sent...
Error: channel martinstabenfeldt-sent: …
Run Code Online (Sandbox Code Playgroud) 从GKE上运行的Rails应用程序收集错误需要哪些步骤?
我已将stackdriver gem添加到我的Rails应用程序中,并且已经使用该errorreporting.errorEvents.create
权限创建了自定义角色.该角色将提供给Compute Engine默认服务帐户
# Add this to config/environments/*.rb
Rails.application.configure do |config|
# Stackdriver Error Reporting specific parameters
config.google_cloud.error_reporting.project_id = "YOUR-PROJECT-ID"
config.google_cloud.error_reporting.keyfile = "/path/to/service-account.json"
end
Run Code Online (Sandbox Code Playgroud)
我手动创建了一个例外
这给了我宝贵的信息:
irb(main):001:0> Google::Cloud::ErrorReporting.report Exception.new(msg: "from console")
=> nil
irb(main):002:0> {:msg=>"from console"} (Exception)
Google::Cloud::PermissionDeniedError: 7:Stackdriver Error Reporting API has not been used in project NNNNN before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/clouderrorreporting.googleapis.com/overview?project=NNNN then retry. If you enabled this API recently, wait a few minutes …
Run Code Online (Sandbox Code Playgroud) ruby-on-rails google-kubernetes-engine stackdriver google-cloud-stackdriver google-iam
我怎么能this
进入我的.map()
循环?它似乎消失了.:-(
我正在创建一个"动态表单",用户可以为其表单指定多行输入.我想迭代所有项目state.items[]
并为它们构建表单输入字段.
例如,表单以"field"和"autocomplete_from"开头.然后,用户可以单击添加新行以在其表单中获取更多行.
102 render: function() {
103 return (
104 <div>
105 {this.state.items.map(function(object, i){
106 return (
107 <div>
109 <FieldName/>
110 <strong> State.autocomplete_from:
{this.state.autocomplete_from} </strong>
// ^^^
// Uncaught TypeError: Cannot read property 'state' of undefined
120 <button onClick={this.newFieldEntry}>Create a new field</button>
121 <button onClick={this.saveAndContinue}>Save and Continue</button>
122 </div>
123 );
124 })}
125 </div>
126 );
Run Code Online (Sandbox Code Playgroud) javascript ×5
reactjs ×5
angularjs ×1
bearer-token ×1
docker ×1
email ×1
gmail-imap ×1
google-iam ×1
kubernetes ×1
mbsync ×1
mongodb ×1
oauth ×1
react-jsx ×1
react-native ×1
stackdriver ×1
state ×1