0

Let say i have 3 textboxes :

  1. product
  2. buyPrice
  3. sellPrice

the product textbox is autocomplete and it works well already, but i want to populate default buyPrice and default sellPrice which i can get from my table and i can include that in json i return. Is it possible?? i googled it but still can't find good example on it.

this is piece of my code :

$( "#product" ).autocomplete({
    source: '/product/product'
}); 

sample of my Product list json :

["x10","f10","f25"]

And 1 more question. Is it possible that i preload My Product List so it no need to go to server everytime user type something in product textbox?

4

1 回答 1

1

使用自动完成的选择事件。

您得到的响应无法与自动完成器一起正常工作。根据文档,需要返回一个带有附加字段的 json 对象,而不是一个简单的数组。像这样:

{
    value: "jquery",
    label: "jQuery",
    buy:   100,
    sell:  200
  },

然后在选择回调中,您可以使用这些字段,例如

 select: function( event, ui ) {
    $( "#project" ).val( ui.item.label );
    $("#buyPrice").val( ui.item.buy );
    $("#sellPrice").val( ui.item.sell );

    return false;
  }

示例小提琴

于 2013-04-24T06:46:00.260 回答