开发者

get dynamic properties in javascript [duplicate]

This question already has answers here: Accessing an object property with a dynamically-computed name (19 answers) Closed 8 years ago.
var tinymce_toolbar = {}
tinymce_toolbar.__default =
{
   script_url: '/cms/libs/js/manual/renders/tiny_mce/tiny_mce.js',  
};
tinymce_toolbar.__simple =
{
   script_url: '/cms/libs/js/manual/renders/tiny_mc开发者_运维问答e/tiny_mce_simple.js',   
};


// Doesn't work
var t = $(this).find('input[name=toolbar]').first().val();
$('.RenderHtmlEditor').tinymce(tinymce_toolbar.t);

// works
var t = $(document).find('input[name=toolbar]').first().val();
$('.RenderHtmlEditor').tinymce(tinymce_toolbar.__default);
$('.RenderHtmlEditor').tinymce(tinymce_toolbar.__simple);

how i do it to be dynamic? Thanks


object['name'] is quite same way as object.name. simply assign a associative attribute and use it as a property.


Instead of dot notation,

tinymce_toolbar.t

Use subscript notation:

tinymce_toolbar[t]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜