javascript - How to dynamically change a combobox's searchAttr based on a radio button in dojo? -
i trying change value of searchattr
of combo box based on radio button. here working snippet of have far.
<html> <head> <title>test</title> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css"> <script> dojoconfig = { parseonload: true } </script> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script> <script type="text/javascript"> require([ "dojo/store/memory", "dijit/form/combobox", "dojo/domready!" ], function(memory, combobox) { var infostore = new memory({ data: [{ "prop1": "a1", "prop2": "a2" }, { "prop1": "b1", "prop2": "b2" }, { "prop1": "c1", "prop2": "c2" }] }); var combobox = new combobox({ id: "combo_id", name: "info", store: infostore, searchattr: "prop1" }, "combo_id"); }); </script> </head> <body class="claro"> <div> <input type="radio" name="searchtype" id="search_type_one" /> <label for="search_type_one">search type one</label> <input type="radio" name="searchtype" id="search_type_two" /> <label for="search_type_two">search type two</label> </div> <input id="combo_id" /> <p> <button onclick="alert(dijit.byid('combo_id').get('value'))">get value</button> </p> </body> </html>
here pseudo code trying accomplish
searchattr: function (item){ if (searchtype.value == "one"){ return item.prop1; } else if (searchtype == "two"){ return item.prop2; } }
the vanilla way bind onchange
event handler in require
callback selector input[name=searchtype]
, updating combobox.searchattr
each time change event fires.
there may more dojo-specific way it, can't that!
Comments
Post a Comment