Hello !
Thanks for the efforts, it worked. I just needed to modify it bit, adding a counter and add row to $tmp[‘items’][$i] instead of $tmp[].
Thanks,
Nbt
From: oreales [mailto:oreales@gmail.com]
Sent: Wednesday, August 26, 2009 9:23 PM
To: Naimesh.Trivedi (Gmail)
Cc: fw-general@lists.zend.com; fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Fetch data to Json conversion issue
I see, now you get an array, but not in the "shape" your combo needs it. your fetchall will return a recordsets with rows. This rows when converted to array will be a "single level" array, where each row becomes a value of the array, but not the MULTI-LEVEL you need for combobox. You need to proccess the resulting $data->toArray() to generate the array you need for combobox. what colums/items are you getting in the "fetchAll" array. I want to suppose that your returned data are a row for each "item" you want in the combobox, so you will need to do something like this
$tmp = array(); //array that finally you will be using in the combobox
$tmp['identifier'] = 'name';
$tmp['items'] = array();
foreach ($data->toArray as $key=>$row){
//create a tmp item mapping row colum to item props you need for combo
$item_tmp = array(
'name' => $row['name'],
'label' => $row['name']
)
//add it to $tmp array that you will json_encode and pass to combobox
$tmp[] = $item_tmp;
}
$this->_helper>json($tmp, array('enableJsonExprFinder'=>true));
NOTE: I think you don´t need to "enableJsonExprFinder" in this case, because you are not encoding native javascript expressions.
El 26/08/2009, a las 15:41, Naimesh.Trivedi (Gmail) escribió:
Hello !
Well no it does not work, dijit.form.ComboBox does not getting filled. $data->toArray() converts data to array but not in the format it needs. It needs format like below :
echo "{identifier:'name',items: [
{name:'Champaign', label:'Champaign'},
{name:'Chicago', label:'Chicago'},
{name:'Naperville', label:'Naperville'},
{name:'Wheaton', label:'Alaska'}]}";
}
This is what combo box needs to populate.
In a simple application with dojo.combobox but in Zend, I did as below and it worked.
$arr = array (
identifier=>'name',
items=>array(
array('name'=>'Anytown', 'label'=>'Anytown'),
array('name'=>'Second', 'label'=>'Second')
)
);
echo json_encode($arr);
but now the array is dynamic so how to generate this style array.
I also tried giving
$dojoData= new Zend_Dojo_Data('taskhead_cd',$data, 'taskhead_cd'); and passing $dojodata to
$this->_helper->json($dojodata, array('enableJsonExprFinder' => true));
But that also is not working and I saw in debugger this also does not generate output as mentioned above so may be combobox not getting filled.
Please help on this, what to give now.
Thanks in Advance !
Naimesh
From: oreales [mailto:oreales@gmail.com]
Sent: Tuesday, August 25, 2009 8:38 PM
To: Naimesh.Trivedi (Gmail)
Cc: fw-general@lists.zend.com; fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Fetch data to Json conversion issue
fetchAll will return an Zend_Db_Table_Rowset_Abstract object. This object, store "data" in a "protected" propertie ($_data), so, json_encoding an object will encode the "PUBLIC" properties of an object. I think you can use toArray() method to obtain the data as an array. Try this:
public function gettaskAction()
{
$taskhead = new Taskhead();
$data= $taskhead->fetchAll();
$arr = array (identifier=>'name',
items=>array(
array('name'=>'Bidding', 'label'=>'Bidding'),
array('name'=>'Response-proposal ', 'label'=>'Response-proposal')
)
);
$this->_helper->json($data->toArray(), array('enableJsonExprFinder' => true));
}
Zend_Db_Table_Rowset_Abstrac
El 25/08/2009, a las 14:41, Naimesh.Trivedi (Gmail) escribió:
Dear Sir,
Hello ! Well I am calling ajax request from my javascript function which in turn is called from dojo.combobox onChange event. I want to return Json output to this javascript from my action. It works well on hard coded array $arr but does not work with $data which has actual dynamic table data.
public function gettaskAction()
{
$taskhead = new Taskhead();
$data= $taskhead->fetchAll();
$arr = array (identifier=>'name',
items=>array(
array('name'=>'Bidding', 'label'=>'Bidding'),
array('name'=>'Response-proposal ', 'label'=>'Response-proposal')
)
);
$this->_helper->json($data, array('enableJsonExprFinder' => true));
}
If I put above $arr in place of $data in json call, it works well and populate my comboxbox but putting $data it does not work, might be not proper json format is converted.
Please guide me on this.
Thanks in Advance !
Naimesh
没有评论:
发表评论