当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to bind two object to one in JS

问题描述:

I have a query filter in my code, I want to pass these two queries as one like this:

 case1

con = {'eq':['case1':dosome]}

case2

con = {'eq':['case1':dosome]}

I need to bind these two at the end like this

{'eq':['case1':dosome],'eq':['case2':dosome]}

the key eq should remain same.

网友答案:

Why not use an object with two properties like

{ eq: { case1: dosome, case2: dosome } }
网友答案:

Sounds like you want an array of objects:

var your_array = new Array();
var con1 = {'eq':{'case1':dosome}}
your_array.push(con1)
var con2 = {'eq':{'case2':dosome}}
your_array.push(con2)

You can then use the methods for accessing parts of the array -> http://www.w3schools.com/js/js_array_methods.asp

网友答案:

Use merge() function. Also this will give error: ['case1':dosome]. Try this

<script>
var obj1 = {'eq':{'case1':dosome}};
var obj2 = {'eq':{'case2':dosome}}
var merge = obj1.merge(obj2);
</script>

Hope this helps

网友答案:

You can try this:

{ eq: [
  { condition: 'case1', action: doSome } , 
  { condition: 'case2', action : doSomeOther }
]}
分享给朋友:
您可能感兴趣的文章:
随机阅读: