私はajaxコールを作成し、返された結果を使用してvue.jsを使用してドロップダウンのオプションを生成したいと考えています。 私はこれを行うことができます。ajaxコールからVue.jsのドロップダウンを入力してください
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
の.jsは
new Vue({
el: '...',
data: {
selected: 'A',
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
]
}
})
ファイルしかし、私は私のオプションは、ハードコーディングされたが、代わりにAJAX呼び出しから来ているしたくありません。
function pullEmployees(){
var eventOwnerId = $('#eventOwner').val();
var eventOwnerName = $('#eventOwner :selected').text();
$.ajax({
url: "employees.cfm",
data: {
eventOwnerId: eventOwnerId,
eventOwnerName: eventOwnerName,
method : "updateOwners"
},
success: function(results) {
// results will have a list of objects where each objects has two properties (ID and Value)
}
});
}
私はvue.jsで本当に新しいですし、誰かが助けることができる場合、私は感謝:
Ajax呼び出しは次のようになります。
これまでのところどのような問題がありますか?あなたのコードで唯一現れる唯一の問題は、 'this'があなたの' success'コールバックでVueにならないことです。 – Bert
私の問題は、vueオブジェクトのoptions属性にajax呼び出しの結果を添付する方法がわかりません。私の上記のサンプルでは、私はオプション(テキスト: 'One'、値: 'A'、テキスト: 'Two'、値: 'B'など)をハードコーディングしています。 – DoArNa
オブジェクトがダウンした{id、value}と同じです。彼らは{text、value}である必要がありますか? – Bert