我正在使用node v6.0.0并想使用ES2016(ES6).但是我意识到"导入"语法不起作用.在ES2015中编写模块化代码不是"导入"的基础吗?我尝试使用--harmony_modules选项运行节点,但仍然有关于"导入"的相同错误.这是代码.
没有"导入"的工作代码:
'use strict';
let sum = 0;
class Number {
addNumber(num1, num2) {
return num1 + num2;
}
}
let numberObj = new Number();
sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);
Run Code Online (Sandbox Code Playgroud)
使用"import"操作代码:
server.js
'use strict';
import Number from "./Number";
let sum = 0;
let numberObj = new Number();
sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);
Run Code Online (Sandbox Code Playgroud)
Number.js
'use strict';
export default class Number {
addNumber(num1, num2) { …Run Code Online (Sandbox Code Playgroud) 我使用"draggable"指令来支持图像拖动.但是,根据用户的角色,我需要禁用某些用户组的图像拖动.我使用了以下代码.
<!--draggable attribute is used as handle to make it draggable using jquery event-->
<li ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box">
<!-- Images and other fields are child of "li" tag which can be dragged.-->
</li>
Run Code Online (Sandbox Code Playgroud)
该方法dragSupported在模板范围内并返回true或false.我不想<li>通过使用ng-iffor返回的每个值来创建两个大的重复元素dragSupported().换句话说,我不是在寻找以下方法来解决这个问题.
<!--draggable attribute is used as handle to make it draggable using jquery event-->
<li ng-if="dragSupported() ==true" ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box">
<!-- Images and other fields are child …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习React Native并试图运行我的Hello,World!应用程序使用https://facebook.github.io/react-native/docs/getting-started.html#content中给出的步骤
我采取了以下步骤
1. `brew install watchman`
2. `npm install -g react-native-cli`
3. `react-native init hello`
4. `cd hello`
5. `react-native run-ios`
Run Code Online (Sandbox Code Playgroud)
我没有启动iOS应用程序,而是在终端中收到以下错误:
Found Xcode project hello.xcodeproj
Usage: simctl list [devices|devicetypes|runtimes]
Could not parse the simulator list output
Run Code Online (Sandbox Code Playgroud)
我也尝试使用Xcode运行它; 但是Xcode显示了很多编译错误.
以下是我系统的详细信息
以下是Xcode中显示的错误的屏幕截图.
我正在运行Karma来使用Grunt执行单元测试用例.它运行得非常好,但是在测试执行完成后,Karma进程不会自动停止.没有错误/没有日志.以下是config和grunt文件的详细信息.
卡玛 - config.js
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: './../../../../',
// frameworks to use
frameworks: ['jasmine'],
// generate js files from html templates
preprocessors: {
'ThemeLibrary/client/templates/categoryview/Category.html': 'ng-html2js'
},
// list of files / patterns to load in the browser
files: [
//Note: Order of file listing does matter therefore loading using * may cause issue
//Load external libraries
'ThemeLibrary/client/js/vendor/others/underscore-min_1.6.0.js',
'ThemeLibrary/client/js/vendor/jquery/jquery.min-1.9.1.js',
'ThemeLibrary/client/js/vendor/angularjs/angular.min.js',
'ThemeLibrary/client/js/vendor/angularjs/angular-resource.min.js',
'ThemeLibrary/client/js/vendor/angularjs/angular-route.min.js',
'ThemeLibrary/client/js/vendor/angularjs/keypress.js',
'ThemeLibrary/client/js/vendor/angularjs/truncate.js',
'Test/unit/client/lib/angularjs/angular-mocks.js',
'Test/unit/client/lib/jasmin/JasminHelper.js', …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular js来显示加载屏幕.它适用于除REST服务之外的所有REST服务调用以下载文件.我理解为什么它不起作用,因为下载我没有使用$ resource进行任何服务调用; 而不是我使用正常的方法下载文件因此Angular js代码没有任何控制启动/完成服务请求.我尝试使用$ resource来访问这个REST服务但是我从这个服务获取数据,在这种情况下,加载屏幕工作正常,但不确定如何使用此数据显示给用户以角度方式下载.以下是必需的细节.请帮忙.
方法1使用iframe方法:
/*Download file */
scope.downloadFile = function (fileId) {
//Show loading screen. (Somehow it is not working)
scope.loadingProjectFiles=true;
var fileDownloadURL = "/api/files/" + fileId + "/download";
downloadURL(fileDownloadURL);
//Hide loading screen
scope.loadingProjectFiles=false;
};
var $idown; // Keep it outside of the function, so it's initialized once.
var downloadURL = function (url) {
if ($idown) {
$idown.attr('src', url);
} else {
$idown = $('<iframe>', { id: 'idown', src: url }).hide().appendTo('body');
}
};
Run Code Online (Sandbox Code Playgroud)
方法2使用$ resource(不确定如何在屏幕上显示数据下载)
/*Download file …Run Code Online (Sandbox Code Playgroud) 我正在使用apollo 2.0。我首先authUser graphql调用服务器以提供给定的用户名和密码,这会生成jwt令牌并作为响应返回令牌。我确实看到成功登录后将User其存储cache为id键值。我有Buy按钮,我需要做validateSSOSession的给予token。对于validateSSOSession,我需要token从缓存中读取。
我经历了client.readQuery,client.fragementQuery但是两者都不适用于我的情况bcz client.readQuery期望在服务器之前调用过相同的查询,并且我应该具有相同的变量。由于我没有,username/password所以我不能打电话client.readQuery。同样,client.fragementQuery期望id是强制性的。由于我没有,id因此无法使用它。
暂时,我只是data从下面cache进行迭代和过滤User。
const data = client.cache.data.data;
const users = _.values(data).filter(obj=>(obj.__typename==='User' && obj.token));
const token = users[0].token;
// Make graphql call to validate sso
const { data } = await client.query({
query: GET_SSO_USER,
variables: { token …Run Code Online (Sandbox Code Playgroud) 我正在使用angular-slick(它基于基于 jquery 的slick)来实现轮播控制。我有实现分层幻灯片的要求,即一次应显示一张幻灯片,而应在左右两侧半隐藏地显示两张幻灯片。在点击 prev/nex 时,underneeth 幻灯片应位于顶部,顶部的幻灯片应位于下方。
我试图使用 css/code 自定义它,但无法弄清楚该怎么做。以下是我的要求的模型。我还查看了http://vasyabigi.github.io/angular-slick/ 上给出的示例

请指教。
我是Angular的新手.我相信我在这里缺少一些基本的东西.
我有一个对象,我发布到服务器来创建它.服务器返回对象Id,我需要读取它并更新客户端中的对象.
服务器只返回对象ID,但是,在客户端,我有其他数据,当我执行回调时我无法使用(我无法访问原始数据).
//Get Angular Project module
var app = angular.module("app", ['ngResource']);
//create Project factory
app.factory('Project', function ($resource) {
return $resource('http://cmsanalyticsdev.pearson.com\\:8081/api/projects/:projectid',
{projectid:'@id'},
{update: {method:'PUT', isArray:false}}
);
});
//Controller for testing
app.controller('ApplicationController', function ($scope, Project) {
//Project object
var project = new Project({"name":"New Project Test","thumbnail":"","statusid":"521d5b730f3c31e0c3b1e764","projecttypeid":"521f585c092a5b550202e536","teamid":"521f585a092a5b550202e521","authors":[{"firstname":"Dilip","lastname":"Kumar"}],"projectspecificmetadata":{"isbn13":"345345","guid":"asfas"},"modifiedby":"521f585a092a5b550202e525"}
);
//Create new project
project.$save(project, function (projectResponse) {
project.projectId = projectResponse._id;
alert(project.name);
});
});
Run Code Online (Sandbox Code Playgroud) 我的应用程序在客户端使用Angularjs.我有五个使用相同逻辑的指令.以下是我的代码的必填详情
我有一个纯javascript类作为AppUtilities.js定义了以下方法
var AppUtilities = {
//Get the guid for given collection
getGUID: function (collectionName) {
var prefix;
var guid;
//get first two character
if (!Utilities.isEmpty(collectionName)) {
prefix = collectionName.substring(0, 2);
//Get timestamp
var timestamp = Utilities.getTimestampId();
//concate prefix to get the guid
guid = prefix + timestamp;
}
return guid;
}
};
Run Code Online (Sandbox Code Playgroud)我有五个不同的指令,我需要使用"getGUID()"方法与模板绑定.由于模板只能与范围函数绑定,因此我在所有这五个模板中定义了范围方法,如下所示
scope.getGUID = function (collectionName) {
return AppUtilities.getGUID(collectionName);
}
Run Code Online (Sandbox Code Playgroud)然后在所有五个指令模板中,此方法作为范围变量绑定
<h4 class="guid" id="guid" data-ng-bind-template="{{getGUID('goal')}}"></h4>
Run Code Online (Sandbox Code Playgroud)如何避免将这些方法声明为范围变量并直接AppUtilities.getGUID(collectionName)在HTML模板中使用?
我是新手,并且正在努力学习带路由器的redux.我想将路由作为单独的文件.但是它不能正常工作,因为我无法传递依赖项.以下是代码详细信息.
工作index.js也有路由:
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from 'react-redux';
import {ReduxRouter} from "redux-react-router";
import {Route} from "react-router"
import createBrowserHistory from "history/lib/createBrowserHistory"
import configureStore from './store';
import App from "./containers/App";
import Home from "./components/Home";
import Countries from "./components/Countries";
import {fetchData} from './actions/actions';
const history = new createBrowserHistory();
const store = configureStore();
function loadData() {
store.dispatch(fetchData('https://restcountries.eu/rest/v1/all'))
}
ReactDOM.render(
<Provider store={store}>
<ReduxRouter>
<Route history={history}>
<Route component={App}>
<Route path='/' component={Home} />
<Route path='/countries' component={Countries} onEnter={loadData} />
</Route> …Run Code Online (Sandbox Code Playgroud) angularjs ×6
javascript ×2
apollo ×1
download ×1
ecmascript-6 ×1
es6-modules ×1
graphql ×1
gruntjs ×1
jquery ×1
karma-runner ×1
node.js ×1
react-apollo ×1
react-native ×1
react-router ×1
reactjs ×1
slick.js ×1