为什么以下工作?
<something>.stop().animate(
{ 'top' : 10 }, 10
);
Run Code Online (Sandbox Code Playgroud)
虽然这不起作用:
var thetop = 'top';
<something>.stop().animate(
{ thetop : 10 }, 10
);
Run Code Online (Sandbox Code Playgroud)
为了使它更清晰:目前我无法将CSS属性作为变量传递给animate函数.
解释我需要什么有点困难,所以我会使用一些非工作代码:
function createSimpleObjet(name, value){
return {
name: value
};
}
//create it
var obj = createSimpleObject('Message', 'Hello World!');
//test it:
alert(ojb.Message); //should alert 'Hello World!'
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我仔细阅读了redux-actions教程,并对他们使用(我相信的)解构感到困惑.下面是一个示例(increment&decrement是函数返回的createAction函数).
const { createAction, handleActions } = window.ReduxActions;
const reducer = handleActions(
{
[increment]: state => ({ ...state, counter: state.counter + 1 }),
[decrement]: state => ({ ...state, counter: state.counter - 1 })
},
defaultState
);
Run Code Online (Sandbox Code Playgroud)
这是另一个使用的例子:
const { createActions, handleActions, combineActions } = window.ReduxActions;
?
const reducer = handleActions(
{
[combineActions(increment, decrement)]: (
state,
{ payload: { amount } }
) => {
return { ...state, counter: state.counter + amount …Run Code Online (Sandbox Code Playgroud) 我有这个简单的对象.
var myobj = {
id: value
}
Run Code Online (Sandbox Code Playgroud)
但是我没有名为"id"的属性,而是希望属性标识符为以下值:
$(this).attr('id');
Run Code Online (Sandbox Code Playgroud)
我不能预设这个,因为我不知道元素的ID.我希望能够获得我的房产价值
<id-of-element>.id
Run Code Online (Sandbox Code Playgroud)
我明白我不能这样做:
var myobj = {
$(this).attr('id'): value
}
Run Code Online (Sandbox Code Playgroud)
但我怎么解决呢?:)