如何在模板prop DateTimeSlot Picker从url传递Json数据?



这是https://jsbin.com/rukubifana/edit?html,console,output DateTimeSlotPicker我想用

var slots = [];
$.getJSON( "/schedule/slots/free/1/30/", function( json ) {
$.each(json, function (key, val) {
slots.push(val);
});
datetimeSlotPicker.slots = slots
});

您能提供更多的信息吗?例如,您是否有控制台错误?

理论上,建议的代码应该可以工作。

同样,我会将slots的声明移动到getJSON回调中。这将导致更好的封装。最重要的是,这里最好使用const,因为引用在执行过程中永远不会改变。

你甚至可以放弃jQuery,直接使用fetch。

async function requestSlots() {
const json = await fetch(request).then((response) => response.json());
const slots = Object.values(json);
datetimeSlotPicker.slots = slots;
}

最新更新