Wednesday, 15 April 2015

ruby - How do you reject a JSON key in jQuery? -



ruby - How do you reject a JSON key in jQuery? -

i have json payload , i'd utilize in several places , wondering how reject 2 keys this.

@metatagsadvanced = { app: { comparison: ['was', 'was not'], value: ['opened in lastly 2 days', 'opened in lastly 2 weeks', 'opened in lastly month'], enabled: true }, appversion: { comparison: ['equals', 'not equal', 'greater than', 'less than', 'greater or equal', 'less or equal'], value: 'string', enabled: true }, controlgroup: { comparison: ['less than', 'less or equal', 'greater than', 'greater or equal', 'equals'], value: 'number', numberoptions: {min: 1, max: 10}, enabled: true }, country: { comparison: ['is', 'is not'], value: 'country', enabled: true }, deliverable: { comparison: ['is', 'is not'], value: ['push notification','local force notification', 'app originated push', 'in-app alert', 'in-app content', 'sms', 'mms', 'email', 'rich message'], enabled: true }, event: {comparison: {eventnumber: ['did occur n days ago', 'did occur greater n days ago','did occur greater or equal n days ago','did occur less n days ago','did occur less or equal n days ago', 'did not occur n days ago','did not occur greater n days ago','did not occur greater or equal n days ago','did not occur less n days ago','did not occur less or equal n days ago'], standards: ['did occur', 'did not occur']}, value: 'events', enabled: true}, installdate: { comparison: ['before', 'was', 'after', 'within', 'days ago', 'greater n days ago', 'greater or equal n days ago','less n days ago', 'less or equal n days ago'], value: 'date', enabled: true }, language: { comparison: ['is', 'is not'], value: 'language', enabled: true }, lastopendate: { comparison: ['before', 'was', 'after', 'within', 'n days ago', 'greater n days ago', 'greater or equal n days ago', 'less n days ago', 'less or equal n days ago'], value: 'date', enabled: true }, os: { comparison: ['is', 'is not'], value: ['android', 'ios'], enabled: true }, pushopenrate: { comparison: ['greater or equal', 'less or equal'], value: ['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1'], enabled: true }, segment: {comparison: ['is in'], value: 'segments', enabled: true}, sessions: { comparison: ['less than', 'greater than'], value: 'number', numberoptions: {min: 1}, enabled: true }, tag: {comparison: {string: ['is', 'is not', 'contains'], double: ['equals', 'not equal to', 'less than', 'greater than', 'less or equal', 'greater or equal'], timestamp: ['before', 'after', 'was', 'within', 'n days ago', 'greater n days ago', 'greater or equal n days ago','less n days ago','less or equal n days ago'], segment: ['is in', 'is not in'], standard: ['exists', 'does not exist']}, value: 'tags', enabled: true}, timezone: {comparison: ['is', 'is not'], value: 'timezone', enabled: true} }

so i'm wanting insert instance can see below. however, how alter code reject/exclude 'segment' , 'timezone' key above?

filters = $.extend({}, @metatagsadvanced)

any help appreciated allow me refactor of code! (i'm using coffeescript, hence why it's formatted way is!)

cheers

i'd utilize utility library lodash or underscore more robust solution, if didn't want rely on native prototype methods on array. intermittent log statements show how gets built up.

jsfiddle here: http://jsfiddle.net/trqg8/

jquery only sometags = foo: {foo: 'bar'} bar: {foo: 'bar'} baz: {foo: 'bar'} _keys = (obj)-> $.map(obj, (value, key)-> key) # seems odd key lastly appears way jquery 2.1.0 works. console.log _keys(sometags) # => ["foo", "bar", "baz"] _in = (arr, key)-> arr.indexof(key) != -1 console.log _in(_keys(sometags), 'foo') #=> true # there native filter function array.prototype _filter = (obj, keys...)-> objkeys = _keys(obj) # poor man's cut down ob = {} k in objkeys ob[k] = obj[k] unless _in(keys, k) ob console.log _filter(sometags, 'bar') #=> object {foo: object, baz: object} console.log $.extend({}, _filter(sometags, 'bar', 'baz')) #=> object {foo: object} underscore

in contrast, using underscore this:

sometags = foo: {foo: 'bar'} bar: {foo: 'bar'} baz: {foo: 'bar'} console.log _.extend({}, _.omit(sometags, 'bar'))

jsfiddle: http://jsfiddle.net/nusm8/1/

jquery ruby json coffeescript

No comments:

Post a Comment