在我的应用程序中,我有分配作业的学生。每次创建学生时,我都会循环遍历当前作业并更新每个学生的作业数组。
我的问题是当我创建作业时。不仅需要创建该作业,而且创建后我还需要将其分配给特定的学生。
我已将我的应用程序分成三个减速器;班级、学生和作业。
如何从作业缩减器更新我的学生状态?我需要等到作业创建完毕,然后将作业数组分配给每个学生。也许我可以发送一个操作,然后发送另一个操作?
case actionTypes.CREATEHOMEWORKS:
// Get new homework description
const newHomework = action.newHomework
// Get the currently active class
const activeClass = action.activeClass.key;
// Get users current browser data
const dateCreated = getCurrentDate();
// Generare a new UID
const key = guid();
// Create a new homework object
const homework = { key: key, class: activeClass, dateCreated: dateCreated, description: newHomework };
// Get the current homework array
const homeworks = JSON.parse(JSON.stringify(state.homeworks));
// …Run Code Online (Sandbox Code Playgroud) 问题无法在与节点一起旋转的javascript文件中加载本地JSON文件.
问题很简单,但我没有在浏览器中提供javascript文件.我有一个具有逻辑的javascript文件,然后我将其旋转:
node main.js
Run Code Online (Sandbox Code Playgroud)
我搜索了一些解决方案,他们建议使用JQuery或XMLHttpRequest,但它们似乎遇到了与我在浏览器中没有服务的事实相关的问题.
我正在使用树莓PI从红外温度传感器获取数据.我使用python来计算电压,转换为摄氏度,然后将其导出为JSON文件.然后我计划将此文件加载到我的javascript文件中,然后配置角度火灾数据库并推送此数据.
我有一个前端应用程序,然后将其拉下来并向用户显示最终数据.
如果我使用JQuery:
$.getJSON("test.json", function(json) {
console.log(json); // this will show the info it in firebug console
});
Run Code Online (Sandbox Code Playgroud)
$.getJSON is not a function even though I am requiring jQuery.
Run Code Online (Sandbox Code Playgroud)
如果我使用纯javascript,我明白了
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'my_data.json', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Angular中的服务,该服务将应用程序的状态保存在字符串变量中。我正在使用RxJS来使用BehaviorSubject,然后我的组件订阅了BehaviorSubject的可观察对象。
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Injectable } from '@angular/core';
@Injectable()
export class StateService {
private sourceState = new BehaviorSubject<string>('Default State');
currentState = this.sourceState.asObservable();
constructor() { }
setState(state: string) {
this.sourceState.next(state);
console.log(this.currentState);
}
}
Run Code Online (Sandbox Code Playgroud)
我的组件都在NgOnInit生命周期中订阅了此可观察的消息。
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../../services/auth.service';
import { StateService } from '../../services/state.service';
import { Router } from '@angular/router';
import 'rxjs/add/operator/filter';
import { Location } from '@angular/common';
@Component ({
selector: 'app-nav',
templateUrl: './nav.component.html',
styleUrls: …Run Code Online (Sandbox Code Playgroud) javascript ×2
angular ×1
node.js ×1
observable ×1
reactjs ×1
reducers ×1
redux ×1
rxjs ×1
typescript ×1