使用 Ajax.InPlaceCollectionEditor 动态更新自动选择值选项
我正在使用 Scripaculous 就地集合编辑器向用户展示要动态分配给联系人的客户列表。我正在传递 文档 中详细说明的值参数,因此当选择时生成后,它将自动选择当前关联的客户(如果还没有提供默认值)。
这种方式效果很好,除非用户第二次单击“编辑我”字段时选择原始值,而不是客户这是最近选择的。这是因为对 InPlaceCollectionEditor 的原始调用没有改变。我的问题是,是否有任何方法可以更新自动选择值,而无需动态更新整个 scriptaculous 调用(这意味着通过 ajax 再次选择所有客户,这是可能的,但并不理想。)
这是代码:
<div id="editme">Test 1</div>
<script type="text/javascript">
new Ajax.InPlaceCollectionEditor(
'editme',
'/usercustomer/editCustomer/id/811',
{ collection: [['192981', "Test 1"],['192893', "Test 2"],['192894', "Test 3"] ... ],
ajaxOptions: {method: 'get'}
, value: 192893 } // specifying the value parameter auto selects object id 192893
);
</script>
这是InPlaceCollectionEditor 或者还有其他方法可以解决这个问题吗?
I'm using Scripaculous' in place collection editor to present the user a with list of customers to assign to a contact dynamically. I am passing a value parameter as detailed in the documentation so when the select is generated it will auto-select the current associated customer (if there is not one already the default is provided.)
This works well except when the user clicks on the 'edit me' field a second time the original value is selected, not the customer that was selected most recently. This is because the original call to InPlaceCollectionEditor is unchanged. My question is whether there is any way to update the autoselect value without dynamically updating the entire scriptaculous call (this would mean selecting all the customers again via ajax, which is possible but not ideal.)
Here is the code:
<div id="editme">Test 1</div>
<script type="text/javascript">
new Ajax.InPlaceCollectionEditor(
'editme',
'/usercustomer/editCustomer/id/811',
{ collection: [['192981', "Test 1"],['192893', "Test 2"],['192894', "Test 3"] ... ],
ajaxOptions: {method: 'get'}
, value: 192893 } // specifying the value parameter auto selects object id 192893
);
</script>
Is this a limitation of InPlaceCollectionEditor or is there some other way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
传递变量而不是硬编码数字作为“值”。在进行调用之前将该变量设置为初始值或选定值。
Pass a variable instead of the hardcoded number as 'value'. Set that variable to the initial or selected value right before making the call.