我正在使用Backbone和Require.js.一切都很好,但我想在我的应用程序中添加一些单元测试.我决定使用Qunit.js.
在我的main.js文件中,我创建了新对象EventsView:
require.config({
paths: {
jquery: 'libs/jquery',
underscore: 'libs/underscore',
backbone: 'libs/backbone',
qunit: 'test/libs/qunit-1.10.0
}
});
require(['view/eventsView',
'test/eventsView_test',
'test/eventView_test' ], function(EventsView){
var events = new EventsView; //here I create first object my View
});
Run Code Online (Sandbox Code Playgroud)
在eventsView.js中, initialize我渲染主视图
define(['jquery',
'backbone',
'underscore',
'collection/eventC',
'model/eventM',
'view/eventView'], function($, Backbone,_,EventC,EventM, EventView,){
var EventsView = Backbone.View.extend({
el: $(".contener"),
initialize: function(){
this.render();
},
....//other functions
});
return EventsView;
});
Run Code Online (Sandbox Code Playgroud)
所以现在我需要在其他文件eventsView_test.js中调用此视图中的函数.我不能这样做,因为View将再次呈现:
define(['jquery','qunit','view/eventsView'], function($,qunit,EventsView){
//var eventsView = new EventsView(); // I can't create …Run Code Online (Sandbox Code Playgroud) 所以我有一个 SVG 元素 - 大圆圈 - 和里面的一组元素。
我想围绕这个大圆圈旋转这些元素。代码非常简单,但我已经很想知道如何在正确的路径(大圆圈)上设置这个圆圈(graph__skils)。正如您在下面的链接中看到的,这个小圆圈在大圆圈上旋转不正确。请帮忙
HTML文件
<section class="graph">
<svg xmlns="http://www.w3.org/2000/svg"
width="670"
height="696"
viewBox="0 0 670 696">
<g>
<g class="graph__middle">
<path fill="#3f9" d="M345 264c34.794 0 63 28.206 63 63s-28.206 63-63 63-63-28.206-63-63 28.206-63 63-63z"/>
</g>
<g class="graph__design" >
<g class="graph_mainCircle">
<path fill="none" stroke="#cf9" stroke- linecap="round" stroke-linejoin="round" stroke-miterlimit="50" d="M345 197c71.797 0 130 58.203 130 130s-58.203 130-130 130-130-58.203-130-130 58.203-130 130-130z"/>
</g>
<g class="graph__skills">
<g class="graph__middle">
<path fill="#cf9" d="M445.053 387c11.052 0 20.012 8.954 20.012 20s-8.96 20-20.012 20-20.012-8.954-20.012-20 8.96-20 20.012-20z"/>
</g>
</g> …Run Code Online (Sandbox Code Playgroud) 你好我有这样的对象:
var obj = { banana: 1425, orange: 1683}
Run Code Online (Sandbox Code Playgroud)
我需要基于项目创建的对象数组.例如:
[{name: banana, value: 1425}, {name: orange, value: 1683}]
Run Code Online (Sandbox Code Playgroud)
我是这样做的:
var fruits = [];
_.each(obj, function(value, name){
fruits.push({
name: name,
value: value
});
});
Run Code Online (Sandbox Code Playgroud)
也许你知道一个更简单的方法?
我在React中遇到了Google Map的问题.一切都很好但是,当我尝试在这张地图中重新渲染其他地方时它不起作用:(我的意思是当我改变城市(例如选择)时使用新的道具(纬度,经度),但城市一地图不改变
import React from 'react';
import ReactDOM from 'react-dom';
import { withGoogleMap, GoogleMap, Marker } from "react-google-maps";
const SimpleMapExampleGoogleMap = withGoogleMap( props => {
console.log("here new props are used", props)
return <GoogleMap
defaultZoom={15}
defaultCenter={new google.maps.LatLng(props.lat, props.lng)}
/>
}
);
class GMap extends React.Component{
constructor(props) {
super(props);
this.state = {
lat: this.props.lat,
lng: this.props.lng
}
}
render() {
console.log("New props ", this.props)
return <SimpleMapExampleGoogleMap
lat={this.props.lat}
lng={this.props.lng}
containerElement={
<div style={{ height: `500px` }} />
}
mapElement={
<div style={{ height: `500px` }} …Run Code Online (Sandbox Code Playgroud) 我想问你如何添加项目到集合,但在其他项目之间.例如.我有一个todoItem {name:todoItem2,date:2012-11-24},我想在集合中的其他项目之间添加它(beodween todoItem1和todoItem3之后不是todoItem3之后).
现在我添加项目如下:
items.push(form_Data);
this.collection.add(new itemM(form_Data));
有什么简单的方法吗?