简体   繁体   English

使用Ajax.InPlaceCollectionEditor动态更新自动选择值选项

[英]Update autoselect value option dynamically using Ajax.InPlaceCollectionEditor

I'm using Scripaculous' in place collection editor to present the user a with list of customers to assign to a contact dynamically. 我正在使用Scripaculous的就地集合编辑器向用户显示要动态分配给联系人的客户列表。 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. 这是因为对InPlaceCollectionEditor的原始调用未更改。 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.) 我的问题是,是否有任何方法可以在不动态更新整个脚本调用的情况下更新自动选择值(这将意味着通过ajax重新选择所有客户,这是可能的,但并不理想。)

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? 这是InPlaceCollectionEditor的限制还是有其他解决方法?

Pass a variable instead of the hardcoded number as 'value'. 将变量而不是硬编码数字作为“值”传递。 Set that variable to the initial or selected value right before making the call. 在进行调用之前,将该变量设置为初始值或选定值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM