我正在使用AngularUI路由器,我正在尝试嵌套/子链接.
一切正常,但我如何在联系人选项卡中选择/激活链接?
基本上,我需要能够在加载联系页面时选择/主动联系一个链接.目前它不会出于某种原因阅读,controlleroneCtrl除非我点击链接联系一个.
angular
.module ('myApp', ['ui.router'
])
.config (['$urlRouterProvider', '$stateProvider', function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise ('/summary');
$stateProvider.
state ('summary', {
url: '/summary',
templateUrl: 'summary.html',
controller: 'summaryCtrl'
}).
state ('about', {
url: '/about',
templateUrl: 'about.html',
controller: 'aboutCtrl'
}).
state ('contact', {
url: '/contact',
templateUrl: 'contact.html',
controller: 'contactoneCtrl'
})
// Sub page
.state('contact.one',{
url: '/contact.contactone',
templateUrl: 'one.html',
controller: 'contactoneCtrl'
})
// Sub page
.state('contact.two',{
url: '/contact.contacttwo',
templateUrl: 'two.html',
controller: 'contacttwoCtrl'
});
}]);
Run Code Online (Sandbox Code Playgroud)
Plunker:http://plnkr.co/edit/DWjp5M6kJt2MyBrasfaQ?p=preview
我有这个非常简单的Component,它连接到redux状态并返回{fruit, vegetables}.一切正常,但是假设我在Component中有一个图表,如果仅从vegetableAPI 更新,则每次都会重新创建图表.
这是我的组件:
const Products = ({ fruit, vegetable }) =>
<div className='Products'>
<div>{vegetable.map(....logic here)}</div>
<div>{Math.random()}</div> // this is to illustrate the component is rendering every time
<Graph>Here will be a chart or a graph with fruit</Graph> //but it gets re-rendered even though there is no new fruit
</div>
const mapStateToProps = (state) => {
return {
fruit: state.data.fruit,
vegetable: state.data.vegetable,
}
}
export default connect(mapStateToProps)(Products)
Run Code Online (Sandbox Code Playgroud)
在我看来,无论哪个状态更新,它都会重新呈现整个组件.
有办法防止这种情况吗?
我设置了 mongodb,并将日期和时间与其他数据一起存储。问题是,当我收到返回的数据时,日期和时间的格式很奇怪,我不确定如何使用 JavaScript 或 jQuery 处理这个问题。
我的架构:
var carSchema = mongoose.Schema ({
carType: String,
notes: String,
created: {type: Date, default: Date.now}
});
Run Code Online (Sandbox Code Playgroud)
这就是我在 JavaScript 对象中得到的:
created: "2015-03-15T14:01:16.447Z"
Run Code Online (Sandbox Code Playgroud)
如何将其转换为时间和日期?
有人可以帮忙吗?
当我尝试将简单的 ES5 代码转换为 ES6 时,我有点困惑。
假设我有这个代码块:
var obj = {num: 2}
var addToThis = function (a, b, c) {
return this.num + a + b + c
}
// call
console.log(addToThis.call(obj, 1, 2, 3))
// apply
const arr = [1, 2, 3]
console.log(addToThis.apply(obj, arr))
// bind
const bound = addToThis.bind(obj)
console.log(bound(1, 2, 3))
Run Code Online (Sandbox Code Playgroud)
上面的一切都按预期运行顺利。
但是一旦我开始使用诸如 const 和箭头函数之类的 ES6 特性,就像这样:
const obj = {num: 2}
const addToThis = (a, b, c) => {
return this.num + a + b + c …Run Code Online (Sandbox Code Playgroud) javascript ×2
angularjs ×1
binding ×1
ecmascript-6 ×1
jquery ×1
mongodb ×1
react-redux ×1
reactjs ×1
redux ×1
this ×1