簡體   English   中英

Yii php x可編輯,使用select2可編輯的遠程源

[英]Yii php x-editable, using remote source for select2 editable

X可編輯的API說我可以使用:

//remote source (simple)
$('#country').editable({
    source: '/getCountries',
    select2: {
        placeholder: 'Select Country',
        minimumInputLength: 1
    }
})

用於定義select2可編輯字段,並使用來自'/getCountries'的遠程源,但是我真的卡在getCountries去的地方。 我知道可編輯在ajax上有效。 這是控制器中的ajax函數嗎? 如果是:

  • 我該如何定義函數以及應在'source:'什么?
  • 如何定義列表將來自的絕對URL? 以及如何格式化數組?

抱歉,我尚未完全弄清可編輯內容的語法。 非常感謝!

在您的控制器中,您應該具有以下內容:

public function actionGetCountries() {
    some code here
}

此代碼將收集所有國家/地區(我想是從db中獲得的?),並將它們作為數組返回(以填充select2)。

//remote source (simple)
$('#country').editable({
    source: 'getCountries.php',
    select2: {
        placeholder: 'Select Country',
        minimumInputLength: 1
    }
})

創建getCountries.php並將其放入其中:

<?php
$array = array(
               array("id"=>1,text=>"Great Britain"), 
               array("id"=>2,text=>"United States")
);
echo json_encode($array);
?>

完成!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM