我是React的新手并试图通过属性传递对象但是会出现以下错误.
Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {title}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of MeetingComponent.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
Main.jsx
import React from 'react';
import MeetingComponent from '../components/Meeting.jsx';
let meeting = {
title: 'Some title'
};
class AppComponent extends React.Component {
render() {
return (
<div className="index">
<MeetingComponent dataMeeting={meeting} />
</div>
); …Run Code Online (Sandbox Code Playgroud) 我对Observables很新.我如何从一个简单的字符串创建Observable?然后订阅它并在它改变时输出它.
那有意义吗?
谷歌搜索我没有运气.可能错误的关键字?
添加一些代码以获得更好的解释
My constructor on service
constructor() {
// Create observable stream to output our data
this.notice = Observable.create(
(observer) => this.observer = observer;
);
};
My method on service
set(string) {
this.notice.subscribe((value) => {
// Push the new value into the observable stream
this.observer.next(string);
}, (error) => console.log('Could not set data.'));
}
Calling service method
setNotice(event) {
event.preventDefault();
// Calling service to set notice
this.noticeService.set('This is a string');
}
Run Code Online (Sandbox Code Playgroud)
我想我在这里做错了什么?但不知道该怎么问.我将不胜感激任何解释.
我希望isLoaderEnabled在数据开始从API下载时打开我的加载程序图标(例如微调器),并在成功接收时将其关闭.什么是关闭它的正确方法?
这是我的以下代码.
我的组件:
this.isLoaderEnabled = true;
this.meetingService.getList();
Run Code Online (Sandbox Code Playgroud)
我的服务:
getList() {
this._http.get('../fake-data/someFile.json')
.map(response => response.json())
.subscribe(
data => {
this.dataStore.meetingList = data;
this.meetingListObserver.next(this.dataStore.meetingList);
},
err => console.log('>>>', 'Could not load meetings list. Error: ', err),
() => console.log('>>>', 'Done with getting meetings list.')
);
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
这是我编译时抛出错误的代码:
export class NoticeService {
public notice: Observable<any>;
private observer: any;
constructor(private translate: TranslateService) {
this.notice = new Observable(observer => {
this.observer = observer;
}).share();
}
create(value: string) {
let translatedValue = this.translate.get(value).value;
this.observer.next(translatedValue);
}
}
Run Code Online (Sandbox Code Playgroud)
输出console.log(this.translate.get(value))是:
ScalarObservable {_isScalar: true, value: "Some proper value!", etc.
Run Code Online (Sandbox Code Playgroud)
输出console.log(translatedValue)是:
"Some proper value!"
Run Code Online (Sandbox Code Playgroud)
错误是:
ERROR in [default] /somePath/notice.service.ts:21:52
Property 'value' does not exist on type 'Observable<any>'.
Run Code Online (Sandbox Code Playgroud)
第21行是:
let translatedValue = this.translate.get(value).value;
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?
更新:
我正在使用ng2-translate,这是get方法:
/**
* Gets the …Run Code Online (Sandbox Code Playgroud) 我有一个像[{...},{...}]这样的对象的数组,我用ng-repeat输出.然后我有一个删除按钮,其中包含删除它的功能.
是否有一种简单的方法可以在AngularJS中删除它,也许使用$ index?或者我需要在每个对象上指定一个ID作为属性?
我需要JSON解码我的Eloquent查询中的某个列.有没有办法在不分开的情况下做到这一点?
到目前为止,我有这个.
public function index()
{
return Offer::all();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel的邮件类,并希望将变量传递给主题.这是我的代码:
public function send()
{
$offer = Offer::find($id)->toArray();
Mail::send('offerMail', $offer, function($message) {
$message->to('some@email.com');
$message->subject('Offer No.' . $offer['code']);
});
}
Run Code Online (Sandbox Code Playgroud)
我正进入(状态
Undefined variable: offer
Run Code Online (Sandbox Code Playgroud)
在定义主题的行内.
这是我的代码:
.put(function(req, res) {
User.findById(req.params.user_id, function(err, user) {
if(err) return res.send(err);
user.dateEdited = new Date();
user.save(function(err) {
if(err) return res.send(err);
return res.status(204).json(customHTTPcodeReponses.updated(user))
});
});
});
Run Code Online (Sandbox Code Playgroud)
我的中间件的一部分称为 customHTTPcodeReponses
updated: function(data) {
return {
code: 204,
status: 'Success',
message: 'Resource updated (or soft deleted)',
data: data
};
}
Run Code Online (Sandbox Code Playgroud)
我想通了, 204 不应该返回任何数据,所以我没有得到任何回报。但我想拥有这些数据,看看真正改变了什么。那我怎么能处理响应代码呢?
请记住,如果我使用
res.status(200).json(customHTTPcodeReponses.updated(user))
Run Code Online (Sandbox Code Playgroud)
数据显示。
如果您需要一些额外的解释,请询问。
我无法解决这种情况-linter向我提出了其他解决方案。这是我的原始代码:
if (arguments[0] && typeof arguments[0] === 'object') {
this.options = extendDefaultProperties(defaultProperties, arguments[0]);
}
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?先感谢您。
我正在通过post方法发送一堆数据。现在,我正在使用一个可以正常工作的解决方案:
$dataClient = new Client;
$dataClient->name = $post['client']['name'];
$dataClient->address = $post['client']['address'];
...
$dataClient->save();
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更短的解决方案?就像发布数组一样,Laravel可以将键映射到db字段吗?
如果您还要添加更多内容(例如计算所得的价值)怎么办?
例:
$dataClient = new Client;
Then map array keys to db keys
$dataClient->someField = someCalculatedValue
$dataClient->save();
Run Code Online (Sandbox Code Playgroud)
先感谢您。
angular ×3
laravel ×3
typescript ×2
angularjs ×1
ecmascript-6 ×1
eloquent ×1
email ×1
express ×1
ionic2 ×1
json ×1
ng-repeat ×1
node.js ×1
observable ×1
reactjs ×1