JS中的$ set(除JQuery外)

时间:2018-07-12 09:23:15

标签: javascript reactjs

我正在浏览Meteor的官方文档,偶然发现他们在其中使用$ something的函数。

$ Javascript中的$仅在我们使用jquery或正则表达式时响起,而我无法使用jquery回忆起

这是我们的代码。

import React, { Component } from 'react';

import { Tasks } from '../api/tasks.js';

// Task component - represents a single todo item
export default class Task extends Component {
  toggleChecked() {
    // Set the checked property to the opposite of its current value
    Tasks.update(this.props.task._id, {
      $set: { checked: !this.props.task.checked },
    });
  }

  deleteThisTask() {
    Tasks.remove(this.props.task._id);
  }

  render() {
    // Give tasks a different className when they are checked off,
    // so that we can style them nicely in CSS
    const taskClassName = this.props.task.checked ? 'checked' : '';

    return (
      <li className={taskClassName}>
        <button className="delete" onClick={this.deleteThisTask.bind(this)}>
          &times;
        </button>

        <input
          type="checkbox"
          readOnly
          checked={!!this.props.task.checked}
          onClick={this.toggleChecked.bind(this)}
        />

        <span className="text">{this.props.task.text}</span>
      </li>
    );
  }
}

在这里,我们在toggleChecked中完成了$set: { checked: !this.props.task.checked },之类的

有人可以向我解释$的工作并向我解释以上代码行吗?

或我在Meteor的另一页上找到的$ ne(这是临时的)

export default withTracker(() => {
  return {
    tasks: Tasks.find({}, { sort: { createdAt: -1 } }).fetch(),
    incompleteCount: Tasks.find({ checked: { $ne: true } }).count(),
  };
})(App);

1 个答案:

答案 0 :(得分:0)

在这种情况下,Meteor似乎在对象中使用Mongo样式修饰符来描述值将要执行的操作。 This page has some meteor informationthis page is is the relevant Mongo doc.