小编be-*_*ied的帖子

反应 - 通过道具传递对象

我是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)

reactjs

11
推荐指数
1
解决办法
3万
查看次数

从字符串中可观察到(Angular 2)

我对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)

我想我在这里做错了什么?但不知道该怎么问.我将不胜感激任何解释.

observable angular

9
推荐指数
1
解决办法
2万
查看次数

Angular2/RxJS - 从Http observable获取数据后更新变量

我希望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)

谢谢.

typescript angular

5
推荐指数
1
解决办法
4282
查看次数

打字稿错误:'Observable <any>'类型中不存在属性'value'

这是我编译时抛出错误的代码:

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)

typescript ionic2 angular

3
推荐指数
1
解决办法
7654
查看次数

如何使用AngularJS从ng-repeat中删除数组中的对象?

我有一个像[{...},{...}]这样的对象的数组,我用ng-repeat输出.然后我有一个删除按钮,其中包含删除它的功能.

是否有一种简单的方法可以在AngularJS中删除它,也许使用$ index?或者我需要在每个对象上指定一个ID作为属性?

angularjs ng-repeat

2
推荐指数
1
解决办法
2万
查看次数

Laravel:在Eloquent中解码JSON

我需要JSON解码我的Eloquent查询中的某个列.有没有办法在不分开的情况下做到这一点?

到目前为止,我有这个.

public function index()
{
    return Offer::all();
}
Run Code Online (Sandbox Code Playgroud)

json laravel

2
推荐指数
1
解决办法
4999
查看次数

Laravel 5:将变量传递给主题

我正在使用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)

在定义主题的行内.

email laravel

2
推荐指数
1
解决办法
1803
查看次数

Express/node.js 204 HTTP 代码响应问题

这是我的代码:

.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)

数据显示。

如果您需要一些额外的解释,请询问。

node.js express

2
推荐指数
1
解决办法
1万
查看次数

使用rest参数代替“ arguments”(prefer-rest-params)

我无法解决这种情况-linter向我提出了其他解决方案。这是我的原始代码:

if (arguments[0] && typeof arguments[0] === 'object') {
  this.options = extendDefaultProperties(defaultProperties, arguments[0]);
}
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?先感谢您。

ecmascript-6

2
推荐指数
1
解决办法
4199
查看次数

Laravel Eloquent:插入数据

我正在通过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)

先感谢您。

laravel eloquent

0
推荐指数
2
解决办法
2万
查看次数